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!
The HTML5 revolution has provided us some awesome JavaScript and HTML APIs. Some are APIs we knew we've needed for years, others are cutting edge mobile and desktop helpers. Regardless of API strength or purpose, anything to help us better do our job is a...
I spent a few months experimenting with different approaches for writing simple, elegant and maintainable media queries with Sass. Each solution had something that I really liked, but I couldn't find one that covered everything I needed to do, so I ventured into creating my...
Every once in a while I come across a plugin that blows me out of the water and the most recent culprit is PassShark: a MooTools plugin that duplicates the iPhone's method of showing/hiding the last character in a password field. This gem of...
HTML5 has introduced many features to the browser; some HTML-based, some in the form of JavaScript APIs, but all of them useful. One of my favorites if the introduction of the placeholder
attribute to INPUT elements. The placeholder
attribute shows text in a field until the...
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.