Can I delete this branch?

End-of-the-year housecleaning time: Our team’s project has accumulated a few* git branches that are almost certainly stale. Some of them were last worked on by people who aren’t even on the project anymore. Still, I wanted to reassure myself before I summarily deleted them. Here are the git commands I was able to round up. What’ve you got?

Start with git checkout master, since these work relative to the current branch and only make sense when that current branch is master.

git branch --merged

lists branches that have been merged to HEAD. (You’ve already made master the current branch, right?) If your branch is in that list, it’s in master and can be deleted.

git branch --contains my-branch-to-delete

lists branches that contain the branch you specified. If master shows up in the list, then master contains your branch.

git log my-branch-to-delete ^master --no-merges

lists commits that are in my-branch-to-delete but are not in master. The ^ means “exclude this branch”, so this is listing commits on my-branch-to-delete, excluding commits that are also on master. If there are no commits in this list, then master contains my-branch-to-delete.

  • Not a few
How transistors work: Illustrated