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!
Firefox OS is all over the tech news and for good reason: Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript. Firefox OS has been rapidly improving...
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...
Before each of the browser vendors we like was providing unique CSS controls, Internet Explorer was setting the tone. One such example is IE's early implementation of CSS filters. Internet Explorer was also the first browser that allowed developers to, for better or worse, customize...
One of the important functions of CSS is to position elements.
Margin
, padding
, top
, left
, right
, bottom
, position
, and z-index
are just a few of the major players in CSS positioning.
By using the above spacing...
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.