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.

Answers


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.


Need Your Help

Either Table Rates or Shopping Cart Rule should be used for "free shipping based on zip code" to work with all methods

magento-1.5 magento magento-1.6

I want to give free shipping for certain regions with specified zip codes. How will i achieve this functionality ?

How to start a fullscreen virtual machine via VirtualBox in the current Mac OS X workspace?

macos virtualbox

Since I updated VirtualBox to 4.3.12, when I start a virtual machine in fullscreen mode, it launches a new workspace with it which is not practical. (Mac OS X 10.8.5)