How to Detect the Default Branch in a git Repository
Over the past few years, many engineering teams have switched their default git branch name from master
to a different, potentially less offensive term. I'm all for choosing to name your default branch whatever you'd like, but not having a universal default branch name can complicate some automation.
So how can we detect the default branch name for a git repository? I use a few chained commands:
git remote show REMOTE_REPO_NAME | grep 'HEAD branch' | cut -d' ' -f5
Swap out REMOTE_REPO_NAME
with the name of the remote/ upstream repository and you'll get the remote repository's default branch name!
My trip to Mozilla Summit 2013 was incredible. I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out. MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...
CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...
Without a doubt, my least favorite form element is the SELECT
element. The element is almost unstylable, looks different across platforms, has had inconsistent value access, and disaster that is the result of multiple=true
is, well, a disaster. Needless to say, whenever a developer goes...
Cool trick ! Except… it works only if your LANG is “en”…
My attempt :
Best regards
This one should be language-neutral:
Hi,
How to find default branch for all the repositories in an organization ?
Hi, thanks for it!
I digged a bit further on git remote and I noticed in its man page the subcommand git remote set-head. Its description begins with “Sets or deletes the default branch (i.e. the target of the symbolic-ref refs/remotes//HEAD)”.
So, it turns out that we can actually do this:
$ sed -e ‘s/^.*\///’ < .git/refs/remotes/origin/HEAD
devel
It is way faster than actually querying the remote server.