Reputation: 2746
I added a new branch to my git repository for a new feature I was adding and forgot to explicitly check it out. I have since changed a lot of files without committing, but I want to be able to commit these changes to the alternate branch, not the master. How can I do this safely?
Upvotes: 22
Views: 9023
Reputation: 468041
You can just checkout the new branch - your uncommitted changes will be carried over to the new branch. (This isn't allowed if your local changes would affect a file that would be changed by switching branch, but in this case it sounds as if the new branch is at the same position as your last commit, so that won't be a problem.)
Upvotes: 24
Reputation: 26825
git stash
git checkout other_branch
git stash pop
Ought to do the trick. You can then commit as normal. See also: git stash manual page
Upvotes: 22