1

I create a new local branch which is called development from the master branch by this command:

git checkout -b development

after the command above executed, on the created branch I open some files make changes, then I move to the origin branch(in my case it is master) open the same file and I can see the changes that I made in the development branch.

While I expect that changes that were made on one branch are not reflected in another branch.

Any idea what can cause this strange behavior or how to fix the issue?

Michael
  • 13,950
  • 57
  • 145
  • 288
  • https://stackoverflow.com/a/246298/7976758: "*The key to remember is that the file was not modified in the git-build 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*" – phd Dec 16 '20 at 16:48

2 Answers2

1

If you are not committing the changes to the branch, they are not in the branch; they are in your working copy or in the index.

When you switch back to origin, Git keeps your modified files (or complain if there are conflicts). In general, it does not make sense to move between branches with uncommitted files. Commit your changes to the branch to keep them there, then switch branches.

I`d suggest reading the Git book to try to understand how Git works. Otherwise, it will be very confusing.

Acorn
  • 24,970
  • 5
  • 40
  • 69
0

do some changes in your code on your dev branch, then you can use these commands

- git stash //to save
- git checkout anotherBranch

when you go back to your branch you can apply your last stash

git stash apply stash@{0}