Skip to main content

Quick tips: Adding an empty master branch

An article from ComputerMinds - Building with Drupal in the UK since 2005
21st Feb 2012

Steven Jones

Senior Developer
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

When I create a git repository for a new project on Drupal.org I don't bother to create a master branch, branches named 6.x-1.x or 7.x-1.x have special meanings and are the ones that we're encouraged to use. However, drupal.org doesn't allow us to change the default branch on d.o itself, so even though there may be no branch called 'master', it's still the default branch, so sometimes cloning a repo will fail:


git clone http://git.drupal.org/sandbox/darthsteven/1268648.git
Cloning into 1268648...
remote: Counting objects: 177, done.
remote: Compressing objects: 100% (176/176), done.
remote: Total 177 (delta 103), reused 0 (delta 0)
Receiving objects: 100% (177/177), 41.22 KiB, done.
Resolving deltas: 100% (103/103), done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.

This is a bit nasty, and you can force people to use the branch name when cloning:


git clone --branch 7.x-1.x http://git.drupal.org/sandbox/darthsteven/1268648.git

Which is what drupal.org will tell people to do on the version control tab.

The real fix

The correct way to get this fixed would be to get this issue about setting a default branch committed and deployed to Drupal.org. But, who knows when that will happen?

A workaround

As an interim workaround that will mean that people cloning your repo don't get an error if they don't specify a branch you can create and push a master branch to the repo.

The best way to do this is to follow the instructions below which basically creates an entire new git tree to work in and pushes that into the master branch. This means that your actual branches and the master branch share no commits at all.

Get yourself a nice clean checkout of your repo, and make sure you really don't have a master branch (if you do you don't need to follow these instructions anyway!)

Then run:


cd /path/to/repo
git symbolic-ref HEAD refs/heads/master
rm .git/index
git clean -fdx
echo "Real code is not kept on the master branch, see one of the other versioned branches instead" > README.txt
git add README.txt
git commit -m "Add a master branch."
git push origin master

You will then have a master branch that contains a single commit, with a single file that tells people to look elsewhere for the code.

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.