Merged branch but when modifying it, master gets modified
A simple/newbie question. I create a branch from the master branch (say "testing"), tried some stuff, and merged it back. Now when I modify the "testing" branch, the local changes are also made on the master branch.
Should I then delete a branch once it is merged and not reuse it? I thought that the branch would just diverge...
To make it clearer, what I do is:
git checkout master git branch testing git checkout testing // Modify files... git add <modified-files> git commit -m 'It worked!' git checkout master git merge testing // Now I go back and edit the testing brach git checkout testing // Edit files... git checkout master // I can see the local changes I made to the testing branch!! (?)
Thanks for any help.
The changes are only in the working copy, they are not in any branch yet. If you do git commit -a -m 'The changes' before checking out master again, your changes are committed to the testing branch.
If you want to just check out master, but you are not ready to commit the changes you made on the testing branch, you can use git stash to put your changes away for now. You have now a clean working copy and can do whatever you want (e.g. check out master and do commits there). After you are done, you can check out testing again and get your previous changes back with git stash pop.
Your second changes are not actually in any branch (you haven't commited them).
This will explain what happens if you change branch with 'dirty' workspace.
You can commit your changes to testing branch and it will diverge from master as usual.