Reputation: 2887
I've got a Git repository for my Android app that I'm trying to overhaul and I want to keep the current working version on hand. I've created a branch for the new development, and checked it out, but when switching to my old branch files that are specific to my new development show up.
My question is this: When you checkout a different branch, does Git delete all the local files from the current branch and then replace them with the new branch's local files? Or does Git just only modify local files when you checkout another branch? I'm using Windows if that makes a difference.
Upvotes: 2
Views: 220
Reputation: 2605
If your working directory is dirty and you don't want to commit just to change branches, you could use git stash
before switching instead.
Something like:
git stash save "cool new feature; not ready for prime time"
Everything is stored safely in your stash stack (you can have more than one set of changes stashed), and your working directory is clean.
When you later switch back to the new work-in-progress branch, you can just
git pop
and you are back where you were, assuming you didn't stash anything else in between.
The section 6.3 of the Git*Pro book has more on the subject.
Upvotes: 1
Reputation: 42879
You must add and commit all new files in your repository for the currently checked out branch in order to have them not showing up when switching to another branch.
The reason is that Git ignores files that have not been added to its index, and quietly leaves them in place when swithcing branches so they would not be removed by mistake.
Upvotes: 1