Add Check What Branches Contain A Specific Commit as a Git TIL

This commit is contained in:
jbranchaud
2026-07-19 10:51:03 -05:00
parent aca5953a2e
commit 1a83ccb852
2 changed files with 29 additions and 1 deletions
+2 -1
View File
@@ -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)
@@ -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.