This article describes a simple fix to an issue (well… One issue or many possible issues), where git fails to pull anything from remote, throwing instead an error somewhat like this:
fatal: no such branch: 'master'
Bah. This stops you from pulling any new changes from remote, and likewise it’ll stop you from pushing your new stuff out there.
Always something going wrong with git, right? But what exactly is the reason this time?
So there I was, just following a guide on docs.microsoft.com. I had just imported a repository from GitHub (this one, if you’re interested https://github.com/staticwebdev/vanilla-api.git) to Azure DevOps and tried to pull it locally. That didn’t work – instead, Visual Studio Code would throw an error and fail.
The error would be somewhat like this:
fatal: no such branch: 'master…master'
git pull --tags From https://dev.azure.com/Organization/Project/_git/Repository
[new branch] main -> origin/main
Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.
Ohhh, okay. Now I see what’s going on.
Somehow, importing a repo from GitHub to AzDO ended up with the primary branch being called differently, and that threw a wrench to git’s pulling gears big time.
Some time ago, Microsoft started provisioning main branches instead of the more traditional master – which admittedly comes with plenty of baggage nowadays – but didn’t automatically update old repositories. Not even their own ones, it seems. My new-ish AzDO repository came with main branch, and didn’t want to have anything to do with primary branches named any other way!
If your default/primary/whateveryoucallit branch is called main, this one won’t do. I have no idea where this project got the default branch from, but it failed.
I mean, to be fair, it’s probably just the way git maintains information about your repository not being very intuitive about odd issues like default branch names not matching. But still – an unseasoned git user will be baffled.
But… How do you work your way around the issue? 🤔
Luckily – it’s simple. Just follow the steps below!
Time needed: 5 minutes.
How to fix a new project throwing “Your configuration specifies to merge with the ref ‘refs/heads/master’
from the remote, but no such ref was fetched.”?
- Open the folder where your solution/project lives in
In Visual Studio Code’s Explorer you can just hit Shift+Alt+R to open the folder where currently active file is located in.
- Navigate to /.git and open a file called HEAD
- Fix the ref
Chances are it’s something along the lines of:
And if your default branch is expected to be called main, it should be:
- Save and retry!
Now you should be good – just pull again and things should work like magic. 🪄
All good now, I hope!
Did it work for you? Did it fail miserably instead? Did you find a better solution? 😁 Let me know in the comments section below!
- How to fix a 403.18 in a virtual application? - September 20, 2021
- GitHub Action fails with “The GITHUB_TOKEN environment variable was not set” - September 15, 2021
- How to download audio files from Vidyard - September 7, 2021