Skip to content


Move commits from master to a new branch

Moves local commits from the master branch to a new branch.

git branch <branch>
git reset HEAD~<n> --hard
git checkout <branch>

# Examples
git checkout master
git add .
git commit -m "Fix network bug"
git branch patch-1
# `patch-1` branch is created containing the commit "Fix network bug"
git reset HEAD~1 --hard # Remove the commit from `master`
git checkout patch-1

More like this

Start typing a keyphrase to see matching snippets.