tags:

views:

89

answers:

2

Somewhat new at Git..

I am working on a project, and had all of my tests passing on the master branch. I then made some changes, and when everything started failing, I realized that maybe I should have made those changes in a different branch. Is there I way I can commit the changes to a new branch without commiting them to my master branch, so that the master still has my passing tests?

+4  A: 

Yes, just create the new branch and check it out:

$ git checkout -b new-branch

Then commit any changes you have. They'll be applied to the new, checked-out branch.

mipadi
ok great.. I misunderstood that section of the docs. Thanks!
Noli
You can switch branches generally with modified files without problem, you'll notice it shows a list of modified/added/delete files when you checkout to a different branch as a reminder that the working tree is not clean. I think in few cases you may be prevented from doing so. Here you switch to a new branch so it is safe. When it doesn't work you can try to stash (git stash) and then apply the stash on the other branch, so you have a clean directory when checking out.
faB
A: 

You can stash your current changes (git stash), switch to the new branch and then apply the changes to the new branch using

git stash pop
Dominik