0

I'm confused with the git checkout command to switch branch. I'm in my other branch, I made changes on a file, but I didn't "git add". I switched to my master branch, and I see the changes on that file.

Why does the changes carried to the master branch when I made the change on the other branch?

Obsidian
  • 3,719
  • 8
  • 17
  • 30
  • 2
    Does this answer your question? [Checkout another branch when there are uncommitted changes on the current branch](https://stackoverflow.com/questions/22053757/checkout-another-branch-when-there-are-uncommitted-changes-on-the-current-branch) – kapsiR Jun 08 '21 at 13:48
  • 1
    Sounds like the file isn't tracked – Paolo Jun 08 '21 at 13:51
  • @Paolo Isn't committed. – phd Jun 08 '21 at 14:04
  • @phd if it was tracked and the changes were not commited, `git` would not let you checkout the branch in the first place – Paolo Jun 08 '21 at 14:05
  • 1
    @Paolo Partially true. Git allows to switch branches with some changes. If the changed file on the new branch is the same as in the old branch Git is not overwriting changes so it allows to switch branch with the modified file in the working tree. – phd Jun 08 '21 at 14:08
  • @phd Fair enough – Paolo Jun 08 '21 at 15:06

0 Answers0