This post was most recently updated on February 19th, 2022.2 min read.
This article describes a simple fix to an issue (well… One 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 will stop you from pushing your new stuff out there.
Always something going wrong with git, right? But what is the reason this time exactly?
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 the main branch, and didn’t want to have anything to do with primary branches named any other way!
If your default/primary/whatever-you-call-it 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 below steps!
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 the 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!
- Automatically get version number from project dependencies in Azure DevOps - March 28, 2023
- Solving “AADSTS90097: An error has occurred during admin consent processing.” issues in your app - March 21, 2023
- How to fix your MAUI Blazor app crashing on startup with “Failed to compare two elements in the array.” ? - March 14, 2023