Creating a branch from a dangling commit's SHA

Use case:

I have a commit in a private Github repo that isn’t in a branch. I can’t get to it locally. I can see it on github dot com /commit/HASH.

You can use the web UI to create new branch pointing to the SHA only if the commit still exists by following these steps:

  1. from the terminal, create a new branch:
    git branch <branch-name> <SHA>

  2. push it:
    git push origin my_new_branch

  3. open the url:
    https://github.com/<owner>/<repo>/tree/new/<SHA>

  4. open the branch selector menu using the button labelled Tree: <SHA> near the top left corner of the page.

  5. type a unique name for your new branch.

  6. press ENTER to create the branch.

I hope this helps!

2 Likes

This is a good tip @andreagriffiths11!

1 Like