sdot257
sdot257

Reputation: 10376

Understand branches in GIT a little better

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.

Upvotes: 3

Views: 170

Answers (2)

pborenstein
pborenstein

Reputation: 476

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.

Upvotes: 3

mipadi
mipadi

Reputation: 411192

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.

Upvotes: 5

Related Questions