brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git branch -vv shows which remote branch each local branch tracks

Git
~/tips/tip-git-branch-vv-tracking

git branch -vv

Lists local branches with the upstream branch each one tracks and the last commit.

After a few months a repository collects local branches, and I forget which ones still have a remote and which ones lost it. git branch -vv puts that in one list.

git branch -vv

Each line shows the branch name, the commit it points at and that commit’s subject. A single -v already adds the relationship to the upstream branch. With the second v the manual says git also prints the name of the upstream branch and, for a branch checked out in a linked worktree, the path of that worktree.

A line looks roughly like this:

* main        a1b2c3d [origin/main] Fix typo in readme
  old-idea    9f8e7d6 [origin/old-idea: gone] Try something
  scratch     4c5d6e7 Notes

In practice gone next to an upstream means the branch was deleted on the remote, often after a merged pull request, and a line without brackets is a branch that was never pushed. That makes it a good first look before cleaning up. Run git fetch --prune first so the information is current, because git only knows what it last fetched.

Caveat: the output is for reading, not for scripts. For a script, git for-each-ref gives a stable format. And do not delete a branch just because it says gone, since local commits that were never pushed still live only there.

Further reading: git branch, -v (Git documentation)

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link