r/git • u/Ex-Traverse • Oct 17 '26
support Question: git stash --> git pull --> git stash pop
Okay, I need to understand/know the standard way to handle this situation...
- I'm working on files in my local repo, got a bunch of unstage changes...
- Someone else just pushed an updated file to the remote-repo
What am I supposed to do? AI is telling me to just do a git stash --> git pull --> git stash pop, but I've put myself in a situation before for doing this... I didn't know git stash can be sorted or even have a date linked to them, or that stuff I stashed several days before is still in there somewhere...
16
Upvotes
42
u/waterkip detached HEAD Oct 17 '26
Just use autostash,
rebase.autoStash. There is alsomerge.autoStash14
u/[deleted] Oct 17 '26
Stash, pull, stash pop should work just fine. If there are conflicts, these will be flagged to you. If you're worried about messing up and losing your changes, you can always make a local commit with them first, and revert to that commit if things go wrong. It's also worth noting that this is essentially the same thing as a rebase (commit your changes, git fetch, git rebase remote-branch), though the stash route doesn't need a new commit.
6
u/prbsparx Oct 18 '26
Generally you should be working in branches, committing your work, and either merging changes from main into your branch, or rebasing your branch from main.
By doing that you don’t have to constantly stash and fix merge conflicts. You pull in main when you’re ready to do the work to fix whatever broke in your code due to changes in main.
4
u/Ok_Specialist413 Oct 18 '26
git stash, git pull, git stash pop is the usual workaround and is totally fine. there is also git pull --autostash which also will do the same, just ensure that you apply pop once and not multiple times or u might find youself pop old random stashes
git pull can be used with or without -r, for me i usually do -r which mean with rebase so i get my history clean. and both case if a conflict appear u'll have to fix it anyways.
You can visit https://gitualize.com/commands/git-pull to learn more about git pull, git pull -r and git pull --autostash, each option is explained and visualized.
and you can visit https://gitualize.com/commands/git-stash to learn more about git stash and git stash pop, and other variations, same thing
1
u/AintNoGodsUpHere Oct 19 '26
Why not simply adding a message to your stash? Then you can always see what index is doing what.
6
u/bostonaholic Oct 18 '26
Stash, pull, pop is fine. The gotcha is that if
pophits a conflict, git keeps the stash around, so old stashes quietly pile up. That's probably how you ended up with days-old stuff in there.What I'd do instead: commit your WIP (even just
git commit -m wip) andgit pull --rebase. Orgit pull --rebase --autostashdoes the stash and pop for you. And checkgit stash listonce in a while andgit stash dropanything you don't need.2
u/rapha3l14 Oct 18 '26
it's best to commit everyday for WIP so it's easier to make sense of the daily changes
2
u/RevRagnarok Oct 18 '26
git stash listand there's an optional--date=relativeif you don't want to do math in your head about how old things are.4
u/thockin Oct 18 '26
Or
commit -am wip, rebase,git reset HEAD^3
u/unndunn Oct 17 '26
You can just commit your local unstaged files before doing the pull. Nothing wrong with doing that.
1
u/kilkil Oct 20 '26
yeah that's what I do usually.
re: tracking work in git stash, yeah it can get a bit rough. better to pop the stash right after pulling so it won't be an issue
1
u/atarivcs Oct 17 '26
stash - pull - pop should work just fine
1
u/Broad-Promise6954 ancient Oct 18 '26
I personally hate
git stashfor various reasons, some good and some bad 😁, but it usually works fine for this kind of situation and in fact the autostash configuration setting others have mentioned makes it smooth and automatic... when it works that is. When it fails it makes a mess that I have found most casual Git users get lost with.Hence my preference, which is: create a new local branch immediately (you can do this with uncommitted work), and then commit to it as a work in progress. You're now free from uncommitted work! You can go to any branch, such as the one you were on moments ago, and do anything, including a simple fast-forward pull that's going to Just Work.
Once you're in a clean and synchronized state, you switch back to your w-i-p branch and can rebase it if you like or continue working without the new update if you prefer, or well anything you want because you're on a personal private branch now.
1
u/WoodyTheWorker Oct 18 '26
People fucking do pull while having no idea what pull actually does.
1
u/Expensive_Bottle4854 Oct 19 '26
Two things that make this whole dance safer:
git stash popcan't apply cleanly, the apply fails and git refuses to drop the entry — the stash stays on the list. The "I put myself in a situation" moments are almost always messy, not lossy.popalways grabs stash@{0}, so a stale one from days ago becomes tomorrow's surprise. Walk the pile withgit stash list(it shows the dates), inspect withgit stash show -p stash@{2}, andgit stash drop stash@{n}anything you don't recognize.After that, stash → pull → pop is fine, or skip the loop entirely with
git pull --rebase --autostash.1
u/Truth-Miserable Oct 19 '26
Respectfully, rtfm.
1
u/CyberJack77 Oct 19 '26
This is how I use git, but I added this to my config so this happens automatically.
This tells git to rebase when pulling (your local commits after the once you pull). And use
autostashonrebase.This does not guarantee there are no conflicts. If you commit often (preferably atomic) any conflict is easily solved during the rebase.
1
u/gfh790 Oct 22 '26
gig stash list first then pull and pop. just be ready to resolve conflicts if they happen1
u/codeguru42 Oct 18 '26
Yes this is a good recommendation. I also recommend that you read more about
git stashto learn why it is so useful.-8
u/apocolipse Oct 17 '26
worktrees