0

I am not sure how did it happen, but now when I make a new branch with this command

git checkout -b new-branch

and make some changes in the new-branch, all those changes will also appear in master. However, it did not used to happen before.

aynber
  • 22,380
  • 8
  • 50
  • 63
Peyman Mahdian
  • 522
  • 4
  • 15
  • This is expected, see also my answer to a similar question: http://stackoverflow.com/a/1394804/112968 – knittl Feb 08 '17 at 19:01

1 Answers1

0

This is expected behavior. Uncommitted changes in your working copy do not belong to any branch, they only live in your working copy. Switching branches will carry these changes over to the other branch, if possible. If not (i.e. the file was changed between both branches), Git will fail with an error message telling you to either commit or stage the changes first.

knittl
  • 246,190
  • 53
  • 318
  • 364
  • Then, how can I work on multiple branches without being worried about what changes are for which branch and push some changes in one branch without stashing other change first? – Peyman Mahdian Feb 08 '17 at 18:52
  • Changes are not for branches, changes only exist in the working directory. They are associated with a branch when committing them. Push (as in `git push`) will only push commits from branches, not unstaged or staged changes. – knittl Feb 08 '17 at 18:55