tags:

views:

87

answers:

2

I'm new to version control and I have a question regarding branching. I have the following branches - "dev" and "master" Say I add or modify a file in dev, I run "git status" and it shows what I've changed. Now, if I switch to the "master" branch, I also see the pending changes when running "git status." Is that supposed to be correct? However, once I run "git commit ..." I'll get the commit messages that pertain to the particular branch I commited through.

I thought and was hoping that each branch would be different. It looks like it is, but I can see where I may get confuse if I'm committing to the wrong branch as I switch back and forth.

+5  A: 

Now, if I switch to the "master" branch, I also see the pending changes when running "git status." Is that supposed to be correct?

Yes. You haven't committed the changes yet. Git allows you to start working on files while one branch is checked out, and then (barring any conflicts) switch to another branch before committing so you can instead commit the changes to that branch.

mipadi
Has this changed? (cf. http://stackoverflow.com/questions/257805/git-switching-branches-windows-uncommited-changes ) Maybe it's configurable?
Douglas Leeder
That's what I meant by "barring any conflicts": If you have local (uncommitted changes in the working tree) modifications that conflict with the state of files in the branch you are switching to, Git will *not* let you switch branches; you'll have to use `git stash` first, switch to the branch, and then un-stash your local modifications.
mipadi
+3  A: 

In Git Magic, Ben Lynn seems to recommend that you do git commit -a before switching branches for this very reason.

You can use git stash to save your change without committing.

pborenstein
very handy tool. much thanks!
luckytaxi