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!
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
With Firefox OS, asm.js, and the push for browser performance improvements, canvas and WebGL technologies are opening a world of possibilities. I featured 9 Mind-Blowing Canvas Demos and then took it up a level with 9 Mind-Blowing WebGL Demos, but I want to outdo...
Every once in a while I find a tiny JavaScript library that does something very specific, very well. My latest find, Fokus, is a utility that listens for text selection within the page, and when such an event occurs, shows a beautiful modal dialog in...
I tend to get caught up on the JavaScript side of the HTML5 revolution, and can you blame me? HTML5 gives us awesome "big" stuff like WebSockets, Web Workers, History, Storage and little helpers like the Element classList collection. There are, however, smaller features in...
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.