Can't push to remote branch, cannot be resolved to branch

GitGithubBitbucketBranchRemote Branch

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

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.

Solution 4 - Git

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...

Solution 5 - Git

It's case-sensitive, just make sure created branch and push to branch both are in same capital.

Example:

git checkout -b "TASK-135-hello-world"

WRONG way of doing:

git push origin task-135-hello-world     #FATAL: task-135-hello-world cannot be resolved to branch

CORRECT way of doing:

git push origin TASK-135-hello-world

Solution 6 - Git

Had the same problem with different casing.

Did a checkout to development (or master) then changed the name (the wrong name) to something else like test.

git checkout development
git branch -m wrong-name test

then change the name back to the right name

git branch -m test right-name

then checkout to the right-name branch

git checkout right-name

then it worked to push to the remote branch

git push origin right-name

Solution 7 - Git

Please use small alphabet letters for branch name, don't use capital letters. It will work.

Solution 8 - Git

For my case, I used to have branch folder (or whatever it is called) with capital letters, then I create a new one with difference casing (lowercase) but git actually create the branch with capital.

I have created a branch like feature-ABC/branch1 before and pushed it. Then I create a branch feature-abc/branch2 (notice the lower-case ABC), and try to push it to remote using git push --set-upstream origin feature-abc/branch2 and get the 'cannot be resolved to branch' error. So I git branch and see that it actually created feature-ABC/branch2 instead of feature-abc/branch1 for me. I checkout again with git checkout feature-ABC/feature2 and push it using the uppercase (feature-ABC/feature2) to solve it.

Solution 9 - Git

I solved this in Windows 10 by using cmd instead of GitBash.

It has to do with character case and how git and command lines handles them.

Solution 10 - Git

I checked out from Feature/name to feature/name and it resolved my issue.

Solution 11 - Git

Maybe your forgot to run git fetch? it's required to fetch data from the remote repo! Try running git fetch remote/branch

Solution 12 - Git

I faced the same issue which was due to going to branch with wrong casing. git let me switch to branch with incorrect casing ie feature/Name instead of feature/name. Found an easier solution than listed above just:

  • commit your changes to 'feature/Name'
  • git checkout master (or develop)
  • git checkout feature/name < with correct casing
  • git push

Solution 13 - Git

For me git status was giving me the incorrect branch name, hotFix/issue-233 instead of hotfix/issue-233. git branch did display the correct branch name.

Solution 14 - Git

The cause in my case was that the correct branch name was in uppercase, but the branch name specified in the push command was in lowercase.

$ git branch --contains=HEAD

The above command will tell you the correct branch name, so push it.

Solution 15 - Git

You might have created similar branch but different case-sensitive-wise, then you have to run:

git branch -D <name-of-different-case-branch>

and then try to push again.

Solution 16 - Git

Slightly modified answer of @Ty Le:

no changes in files were required for me - I had a branch named 'Feature/...' and while pushing upstream I changed the title to 'feature/...' (the case of the first letter was changed to the lower one).

Solution 17 - Git

I had the same problem but was resolved. I realized branch name is case sensitive. The main branch in GitHub is 'master', while in my gitbash command it's 'Master'. I renamed Master in local repository to master and it worked! 

Solution 18 - Git

My 2 cents... This problem occurred in my case because of a typo (uppercase letter) in the branch name. I had 2 branches with almost identical names.

Solution 19 - Git

If one is using folders such as Omegaman/BugFix make sure the case is correct. It seems one can checkout an existing branch as lowercase omegaman/BugFix and attempt to push, it will fail.

Recheckout with the proper casing such as git checkout Omegaman/BugFix to resolve.

Solution 20 - Git

I ran into the same problem caused by incasesensitive in windows system. Use git checkout -b your-new-branch from you current branch and push to remote, then you can find commits in both.

Solution 21 - Git

If you are in local branch, could rename the branch "Feature/Name" to "feature/Name"

git -m feature/Name

if you have problems to make a git push make a checkout in other branch (ex develop) and return to renamed branch

git checkout feature/Name

and try again your git push

Solution 22 - Git

I just had this issue as well and my normal branches start with pb-3.1-12345/namebranch but I accidental capitalized the first 2 letters PB-3.1/12345/namebranch. After renaming the branch to use lower case letters I could create the branch.

Solution 23 - Git

for me I was naming branch as

> Rel4.6/bug/Some-short-description

all I had to do is when using

> git push origin Relx.x/bug/Some-short-description

to write

> git push origin relx.x/bug/Some-short-description

as I used to create branches using small letter r in rel.

so, what caused this issue?

when I listed .git/refs/heads content I found

drwxr-xr-x  4 eslam_khoga  staff   128B Sep 22 20:22 relx.x

but no Relx.x!

and inside it bug and inside bug my branch's name.

So, git try to create a dir with same name but different case letters

but system is not case sensitive.

That's what caused this issue!

Solution 24 - Git

For me, the issue was that I had git and my macOS filesystem set to two different case sensitivities. My Mac was formatted APFS/Is Case-Sensitive: NO but I had flipped my git settings at some point trying to get over a weird issue with Xcode image asset naming so git config --global core.ignorecase false. Flipping it back aligned the settings and recreating the branch and pushing got me back on track.

git config --global core.ignorecase true

Credit: Git is case-sensitive and your filesystem may not be - Weird folder merging on Windows

Solution 25 - Git

I ran into the same issue and noticed that I had mixed up the casing while checking out the branch. I checked out branchName instead of BranchName and when I tried to push to remote, I got the same error.

The fix:

git push --set-upstream origin BranchName

By setting upstream to the correct name, the correct branch was updated on github and I was then able to checkout the correct branch name with

git checkout BranchName 

And it should be up to date with your last push.

Solution 26 - Git

it seems that you try to rename your master branch to Main. by using this command git branch -M Main where you were on master branch. execute this git command, il will work :

git push --all -u

after this you can run git branch to see your branches then you can delete the master branch like this :

git branch -D master

Solution 27 - Git

Know that branch letters are case sensitive, that's what I face, I tried pushing to "header" instead of "Header"

Solution 28 - Git

After having the similar problem, I decided to post what worked for me.

I tried to push new branch to the remote repository with the command:

git push --set-upstream origin <branch name copied from Git console after navigating to the repository location>

and got the following status message:

warning: redirecting to <myRepositoryAdress>

fatal: <branch> cannot be resolved to branch

First of all, we migrated Git and I thought that might be the issue, but not.

The actual problem was:

Instead of having branch named: bugFix/UserName/BranchName, it was written as bugfix/UserName/BranchName in the Git console (notice lowercase f here). I figured that out by typing git branch -a and comparing all existing branches with the one that I am checked out to / want to push. How it happened that the console had lowercase f, I still don’t know. Of course, that the name cannot be resolved to a branch if the name of the actual local branch is different from the name you typed when pushing!

In my SmartGit GUI commit was on the correct branch, but I prefer console and pushing from there, so SmartGit was more like a step to check log of the local state and compare if there is some error in the console.

What I learned from this:

Don’t use git push --all –u as some people suggest in the posts that relate to this error if your goal is to push only one local branch.

Better try to figure out what is exactly wrong and why. Then search for the solution. Maybe you also have a typo or some similar inconsistency.

Solution 29 - Git

Try this for the error: (feature/test is local branch name)

git branch --set-upstream-to=origin/feature/test feature/test

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjleachView Question on Stackoverflow
Solution 1 - GitTy LeView Answer on Stackoverflow
Solution 2 - GitSchwernView Answer on Stackoverflow
Solution 3 - GitmoggersView Answer on Stackoverflow
Solution 4 - GitJGLView Answer on Stackoverflow
Solution 5 - GitSherView Answer on Stackoverflow
Solution 6 - GitNervallView Answer on Stackoverflow
Solution 7 - GitMahesh RView Answer on Stackoverflow
Solution 8 - GitVee TrairattanapaView Answer on Stackoverflow
Solution 9 - GitjulianmView Answer on Stackoverflow
Solution 10 - GitShahView Answer on Stackoverflow
Solution 11 - GitjokerView Answer on Stackoverflow
Solution 12 - GitCorbin HudsonView Answer on Stackoverflow
Solution 13 - GitIvan NietoView Answer on Stackoverflow
Solution 14 - GitjojoView Answer on Stackoverflow
Solution 15 - GitlokoView Answer on Stackoverflow
Solution 16 - GitryzhmanView Answer on Stackoverflow
Solution 17 - GitWaswa RodgersView Answer on Stackoverflow
Solution 18 - GitLuca FilipView Answer on Stackoverflow
Solution 19 - GitΩmegaManView Answer on Stackoverflow
Solution 20 - GitHui LiView Answer on Stackoverflow
Solution 21 - GitRonaldo AlbertiniView Answer on Stackoverflow
Solution 22 - GitPeter BoomsmaView Answer on Stackoverflow
Solution 23 - GitKhogaEslamView Answer on Stackoverflow
Solution 24 - GitMichaelView Answer on Stackoverflow
Solution 25 - GitbediV5View Answer on Stackoverflow
Solution 26 - GitbigtheoView Answer on Stackoverflow
Solution 27 - GitDavid MDView Answer on Stackoverflow
Solution 28 - GitCodeSamuraiView Answer on Stackoverflow
Solution 29 - GitSuibur R.View Answer on Stackoverflow