0

I am using one example here:

  1. git checkout -b b1

    Create a new branch b1, made some changes, such as update file, create a new file, delete a file, etc.

  2. git checkout master and it was succeed!!

    Question 1: how come I can checkout to master without saving changes on branch b1?

  3. And when I run git status on master, actually I am able to see those changes. Why... Is a branch should be sperate with other branches?

Thanks for pointing out if I were wrong.

Ben
  • 946
  • 1
  • 11
  • 19

1 Answers1

2

If you change files and do not commit them, git does not know of those changes. Therefore those changes are not connected to the branch at all.

If you now change the branch and the modified file is the same in both branches, git has no need to update that file and will simply leave the file as it is.

As a rule of thumb: Before doing any important git command (like changing branch or updating branch via pull), always think about your uncommitted changes. - If they are good, commit them. If they are bad, discard them.

Also have a look at https://stackoverflow.com/a/18296840/1870481.

Community
  • 1
  • 1
michas
  • 25,361
  • 15
  • 76
  • 121