What commit did I branch off from?

Featured image for sharing metadata for article

Sometimes, you create a branch off another branch, do some work on it, and want to know what the original branch was pointing at.

For instance, if you're looking to clean up your Git history, but don't want to rebase off origin/HEAD as you know there are some gnarly conflicts you may have to deal with, you want to know the last known "good" commit.

I'd previously look down my commits, work out what the first commit was that didn't look like one of mine on this branch and refer to that SHA.

Instead - via - we can use git merge-base to do this, i.e.:

% git log --graph --oneline
* 895aa796f (HEAD -> ci/dequeued, origin/ci/dequeued) ci: auto-label PRs that have been dequeued from the Merge Queue
* c2785bc5a (upstream/main, upstream/HEAD, main) refactor(oxlint): scope custom JS rules via config overrides (#45266)

% git merge-base HEAD main
c2785bc5a48a423e0c59dcc95921e5a33097d762

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #git.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.