1

I would like to maintain master branch and b1 branch as independent to each other, this is how I've done so far.

I created a brandnew branch called b1

git branch b1
git checkout b1

I open sublime and edited a file called f1.txt, and saved it.

I switch to the master branch

git checkout master

I displayed the content of the file

cat f1.txt

Why I can see the "additional line" I just added when I was on the b1 branch

What did I do wrong???

Please help, thanks.

Artisan
  • 4,042
  • 13
  • 37
  • 61
  • 1
    possible duplicate of [In git, is there a simple way of introducing an unrelated branch to a repository?](http://stackoverflow.com/questions/1384325/in-git-is-there-a-simple-way-of-introducing-an-unrelated-branch-to-a-repository) – Hasturkun Sep 23 '13 at 10:15
  • Did you commit your changes or only saved a file? – Michał Szajbe Sep 23 '13 at 10:50

2 Answers2

2

This is the default behaviour of git.

You can use -f flag to checkout to do "clean checkout" if you like.

The key to remember is that the file was not modified in the b1 branch. It was only modified in your working copy.

Only when you commit are the changes put back into whichever branch you have checked out

It's answered here

Community
  • 1
  • 1
Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
1

You always had to commit the changes before switching to another branch. For example:

git add -A
git commit -m "test"

and now you can switch to the new branch. For example:

git branch test

You can also read my blog post on this topic: http://www.deanpodgornik.si/how-to-collaborate-using-git-merging-simplified/

deanpodgornik
  • 322
  • 2
  • 7