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!
Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices. While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...
Google Plus provides loads of inspiration for front-end developers, especially when it comes to the CSS and JavaScript wonders they create. Last year I duplicated their incredible PhotoStack effect with both MooTools and pure CSS; this time I'm going to duplicate...
I've never met a person that is "ehhhh" about XHTML/javascript tooltips; people seem to love them or hate them. I'm on the love side of things. Tooltips give you a bit more information about something than just the element itself (usually...
Grabbing emails from your Gmail account using PHP is probably easier than you think. Armed with PHP and its IMAP extension, you can retrieve emails from your Gmail account in no time! Just for fun, I'll be using the MooTools Fx.Accordion plugin...
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.