Reputation: 8411
If I have added something in master branch then I decided that it need to be in a purposely created branch, called some-branch
.
Those new files changed in master are now green. I do not want to commit them in master but in the new branch that I have forgot to create befor I have made the changes.
So how to commit changes for a different branch?
Upvotes: 3
Views: 769
Reputation: 1561
Try following:
1. git reset (if changes are staged/added for commit)
2. git checkout -b newbranch
or
git checkout newbranch (if branch is already there)
Another way:
1. git reset (if changes are staged/added for commit)
2. git stash
3. git checkout -b newbranch or git checkout newbranch if branch is already there.
4. git stash pop
Upvotes: 3
Reputation: 126
I think this will work.
If you haven't made a new branch, try this:
git checkout -b mybranch
If you want to move these commits to a branch that already exists, try this:
git checkout existingbranch
Here are some helpful resources that worth checking out:
https://lostechies.com/derickbailey/2010/04/01/git-oops-i-changed-those-files-in-the-wrong-branch/
Also, https://git-scm.com/ has always been a great git resource for me.
Hope this helps. Good luck!
Upvotes: 1
Reputation: 888117
As long as the branch doesn't have conflicting changes, you can git checkout
your new branch with those changes (without committing) and they will remain.
Upvotes: 4