From 1a83ccb852f4ee7daa95efc3420102d0b93bffc3 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 19 Jul 2026 10:51:03 -0500 Subject: [PATCH] Add Check What Branches Contain A Specific Commit as a Git TIL --- README.md | 3 ++- ...what-branches-contain-a-specific-commit.md | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 git/check-what-branches-contain-a-specific-commit.md diff --git a/README.md b/README.md index abc5503..0e7c467 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/). For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter). -_1824 TILs and counting..._ +_1825 TILs and counting..._ See some of the other learning resources I work on: @@ -344,6 +344,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Check How A File Is Being Ignored](git/check-how-a-file-is-being-ignored.md) - [Check If A File Has Changed In A Script](git/check-if-a-file-has-changed-in-a-script.md) - [Check If A File Is Under Version Control](git/check-if-a-file-is-under-version-control.md) +- [Check What Branches Contain A Specific Commit](git/check-what-branches-contain-a-specific-commit.md) - [Checking Commit Ancestry](git/checking-commit-ancestry.md) - [Checkout Old Version Of A File](git/checkout-old-version-of-a-file.md) - [Checkout Previous Branch](git/checkout-previous-branch.md) diff --git a/git/check-what-branches-contain-a-specific-commit.md b/git/check-what-branches-contain-a-specific-commit.md new file mode 100644 index 0000000..d193fe5 --- /dev/null +++ b/git/check-what-branches-contain-a-specific-commit.md @@ -0,0 +1,27 @@ +# Check What Branches Contain A Specific Commit + +The `git branch` command comes with a `--contains` flag that can tell me what +local branches contain a specific commit based on the SHA of that commit. + +```bash +❯ git branch --contains a73d9173c2399069fa202fe65da0a8927814fd84 +* main + jb/migrate-to-basedpyright + jb/migrate-date-files-to-repository-pattern +``` + +I am currently on the `main` branch which is why it shows the `*` next to that +one. This SHA also appears on those other two branches. + +This command could be useful in a variety of situations. + +1. If I'm looking at a commit on a branch and I cannot remember if it has been + integrated upstream yet. This check could tell me (unless commit squashing + happens). +2. If I'm on `main`, as I was above, and I am trying to remember what branch + introduced a commit, this can help with that sleuthing. This assumes I don't + delete branches. +3. Maybe I've just run a `git bisect` to track down a bad commit and I want to + see what are all the local branches that are impacted. + +See `man git-branch` for more details.