Can't push to remote branch, cannot be resolved to branch
I migrated my repos from Bitbucket or Github. I don't think this matters but it's the only thing different. For a little while, I had two remotes set up:
origin: bitbucket
github: github
Then I removed both and pointed origin to github:
git remote remove origin
git remote remove github
git remote add origin https://github....
Test push of develop branch:
git push origin develop
Everything up to date, ok, good.
Create a new branch for some work as per usual:
git checkout -b Feature/Name
Update a file or two. Attempt to push to remote:
git push origin Feature/Name
This results in the error:
fatal: Feature/Name cannot be resolved to branch
Search online for this issue, find some stuff about ensuring HEAD is correct, others about making sure I've got my branch name case correct (though, at this point the branch doesn't exist on the remote yet). Unable to resolve.
Ran this command:
git push --all -u
This got my Feature/Name
branch to github, but still see same behavior as prior:
git push origin develop
git push origin Feature/Name
The first works while the second throws the same error. Why?
I was having this issue as well, and it was driving me crazy. I had something like feature/name
but git branch -a
showed me FEATURE/name
. Renaming the branch, deleting and recreating it, nothing worked. What finally fixed it:
Go into .git/refs/heads
You'll see a FEATURE
folder. Rename it to feature
.
Based on my own testing and the OP's comments, I think at some point they goofed on the casing of the branch name.
First, I believe the OP is on a case insensitive operating system like OS X or Windows. Then they did something like this...
$ git checkout -b SQLMigration/ReportFixes
Switched to a new branch 'SQLMigration/ReportFixes'
$ git push origin SqlMigration/ReportFixes
fatal: SqlMigration/ReportFixes cannot be resolved to branch.
Note the casing difference. Also note the error is very different from if you just typo the name.
$ git push origin SQLMigration/ReportFixme
error: src refspec SQLMigration/ReportFixme does not match any.
error: failed to push some refs to '[email protected]:schwern/testing123.git'
Because Github uses the filesystem to store branch names, it tries to open .git/refs/heads/SqlMigration/ReportFixes
. Because the filesystem is case insensitive it successfully opens .git/refs/heads/SqlMigration/ReportFixes
but gets confused when it tries to compare the branch names case-sensitively and they don't match.
How they got into a state where the local branch is SQLMigration/ReportFixes
and the remote branch is SqlMigration/ReportFixes
I'm not sure. I don't believe Github messed with the remote branch name. Simplest explanation is someone else with push access changed the remote branch name. Otherwise, at some point they did something which managed to create the remote with the typo. If they check their shell history, perhaps with history | grep -i sqlmigration/reportfixes
they might be able to find a command where they mistyped the casing.
Git will let you checkout the current branch with a different casing, and it will fail to find a ref on the remote.
Just found out the hard way.
A similar thing happened to me. I created a branch called something like "Feat/name". I tried to pushed it using :
git push --set-upstream origin Feat/name
I got the same fatal error as you :
fatal: Feat/name cannot be resolved to branch
To solve it I created a new branch as I had very few files impacted. Then I listed my branches to delete the wrong one and it displayed with no cap :
- feat/name
I had used caps before but never on the first caracter. It looks like git doesn't like it...