I have a file in my master git branch called ‘Readme.’ The file has the following text:
This is the master branch
I made a topic branch called ‘justatest’ and edited the ‘Readme’ file inside of it. I edited this file (while the justatest branch was checked out) to say the following:
This is the master branch
This text should only be seen in the ‘justatest’ branch
When I am in the ‘justatest’ topic branch it appears correctly, but when I switch to the master branch, here’s what the file says:
This is the master branch
This text should only be seen in the ‘justatest’ branch
As you can see, it’s making the changes in the master branch even when I have a topic branch checked out! WHY???
The worst part is that if I don’t like the changes I have made in the topic branch and I delete it, the changes REMAIN in the master branch!! Where’s the safety in that???
When you make edits, they are not part of any branch. These changes are only in your working folder. Changing branches while you have some outstanding work not yet committed is allowed – as long as they don’t conflict with the committed version of the files.
In your case it’s even simpler. Since you just made the branch, both master and this new branch point to the same commit. Once you add and commit your changes, switching branches will have the behaviour you are expecting.
your file will be what it was before you branched.
You can flip between 2 last branches you had checked out by repeatedly doing
this is also true of
cd.Take a look at http://progit.org/book for info about the working directory and index.