Git: Move Commits To Another Branch

06 Nov 2012. comments

Let’s say you made a commit to your git repo but then decide you want to stow it away on a different branch and put the current branch back where it was.

Create the new branch, which will be up to the new commit:

git branch foo-branch

Now put the current branch back before the commit:

git reset --hard HEAD~1

Check out the branch still containing the new commit:

git checkout foo-branch

Now ‘foo-branch’ will contain the new commit but the original branch will be where you were before that commit.


Tagged: git source-control

2017 Ben Lakey

The words here do not reflect those of my employer.