When changing branches, it brings modifications to the source branch

3

Good, I have a problem trying to change the branch because when I made the change instead of giving me the message

  

Please, commit your changes or stash them before you can switch branches.

let me change the branch and also brings me the changes of that branch the flow I'm doing is the following:

  

1 - git checkout -b new_branch

     

2- I modify some file in the new_branch

     

3- git checkout origin_branch

I leave a more explanatory image, thank you in advance for the help you can give me.

My question is why the changes made in different branches are transferred between the branches when checking out? The behavior I need is what happens for example if I try to checkout from the develop branch to the master branch:

    
asked by RaKKoS_NeT 27.08.2016 в 08:49
source

1 answer

3

It is the normal operation of git, until you commit the changes, they are not isolated and they remain even if you change branches.

A good habit is to clean the work area before changing. If something has been left halfway and you are in a state where there is no sense in confirming it, it is best to use the temporary quick save , "stash" as comment above. It is a kind of "paper holder"

The workflow would be something like this:

Before changing branches:

# git stash // Esto guarda las modificaciones no confirmadas limpiándolas del área de trabajo

You can check that the changes are no longer

# git status
On branch master
nothing to commit, working directory clean

Then you can change to another branch, confirm other changes

# git checkout otra-rama  
# git add *
# git commit

Go back to the master branch

# git checkout master

And recover the status you saved without confirming:

#git stash apply
    
answered by 27.08.2016 / 17:53
source