Git showing lots of changes and untracked files after checkout
So I’m on a branch, let’s call it
feature/PRO-10 and I want to switch to another branch to quickly check the state of a piece of code. I do a
git stash to stash my changes and then a
git checkout bugfix/PRO-13 to go to the branch I want to look at code on. I finish what I want to do on this branch (without making any changes) and do a
git checkout feature/PRO-10 to get back to the branch I was developing on. I’m about to do a
git stash pop but wait! There’s a behemoth of modified and untracked files along with other changes.
How did they turn up? I never did any sort of merge. I may have done a
git pull to get up-to-date with
bugfix/PRO-13 but I don’t see why that would make loads of changes that follow me to my original branch.
The worst thing is sometimes I’ll do a
git stash pop before doing a
git status, meaning I’ll probably have my original changes mixed in with all this other gumph that seemingly came out of nowhere.
Where are these changes coming from and are they safe to get rid of?
One Solution collect form web for “Git showing lots of changes and untracked files after checkout”
git checkout, git tries to delete the things that don’t exist in the destination branch. If you’ve got a virus scanner running, it’ll leave them behind or prompt you. If you’re confident you have everything either stashed or committed, you can
git reset --hard to get rid of these abandoned files. Be careful though as this specifically says “revert all local changes without warning” so make sure that’s really what you wanted to do.