Skip to content

Instantly share code, notes, and snippets.

@aont
Last active September 21, 2025 10:20
Show Gist options
  • Select an option

  • Save aont/cc926fe652ec6d80d378eefeccac9be3 to your computer and use it in GitHub Desktop.

Select an option

Save aont/cc926fe652ec6d80d378eefeccac9be3 to your computer and use it in GitHub Desktop.

Creating a Git Branch from HEAD^

When working with Git, sometimes you may want to create a new branch based on the commit before the current HEAD. In Git notation, HEAD^ refers to the parent of the current commit.

Command

To create a branch from HEAD^, run:

git checkout -b <new-branch-name> HEAD^

This will:

  • Create a new branch named <new-branch-name>.
  • Point it to the commit one step before the current HEAD.
  • Switch your working directory to the new branch.

Examples

git checkout -b fix-before-change HEAD^

This command creates a branch called fix-before-change starting from the commit just before your latest commit.

Notes

  • HEAD^ means one commit before HEAD.
  • HEAD^^ means two commits before.
  • Alternatively, you can use the tilde (~) notation: HEAD~3 means three commits before.

If you only want to move temporarily to the parent commit (without creating a branch), you can use:

git checkout HEAD^

This places you in a detached HEAD state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment