261

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?

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
jleach
  • 7,410
  • 3
  • 33
  • 60
  • 1
    What branch were you on when you made `Feature/Name`? Are you *sure* `Feature/Name` exists and that's the checked out branch? Check with `git branch`. – Schwern Jun 26 '16 at 03:23
  • @Schwern - Only three branches existed (locally and on remote): develop, test and master. Once a branch is cleaned up and merged back to develop I delete them locally (and remotely if applicable). I'm certain there were only my three - I haven't opened the project in a while and first thing I did was check and make sure I had no loose branches. – jleach Jun 26 '16 at 03:32
  • Does that mean you ran `git branch` to verify `Feature/Name` exists locally? Don't trust a GUI or IDE. Also, did you get the case right? – Schwern Jun 26 '16 at 03:37
  • How about `git push origin Feature/Name:Feature/Name`? – ElpieKay Jun 26 '16 at 03:40
  • Now I'm pissed... not sure why it didn't work in the first place, but after using `git push --all -u` I have the new branch in github, but still couldn't push from local, right? Here's what happened with that... the actual branch name is `SQLMigration/ReportFixes` and what is in github is `SqlMigration/ReportFixes`. So, now I can `git push origin SqlMigration/ReportFixes` - whytf does github change casing for me? Agh. – jleach Jun 26 '16 at 03:56
  • @Schwern - yes, `git branch` is how I check, I rarely use GUIs for git. @ElpieKay - tried that too, got an error, then was going to grab a screenshot and realized the oh-so-helpful auto-case-change in the github branch per my previous comment. – jleach Jun 26 '16 at 03:57
  • @jdl134679 then try `git push origin Feature/Name --`. Is it possible that Feature/Name can be resolved as a file in your repo? – ElpieKay Jun 26 '16 at 04:50

33 Answers33

832

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.

Ty Le
  • 8,494
  • 1
  • 11
  • 7
  • The problem is that the remote and local branch have different cases. There are a number of ways to solve this. Either rename the branch or push the branch using the correct case. I just pushed to the remote branch with the correct case, checkout out the branch using the same case. Then the old branch with the incorrect case simply disappeared from branch -a – Peter Suwara Oct 30 '19 at 08:10
  • For the quick and not quite as nice fix, try `git checkout -b new-branch-name` and just use another branch name – Ben Gooding Feb 12 '21 at 16:55
  • Excellent, did work as expected. Was not aware of the capital folder name against lowercase folder name would cause an issue. – invinciblemuffi Jan 19 '23 at 03:47
52

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 'git@github.com: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.

Community
  • 1
  • 1
Schwern
  • 153,029
  • 25
  • 195
  • 336
  • I ran into this problem when I changed the case of characters in the branch name on OS X. Changing them back resolved the issue. – Steven C. Howell Mar 08 '17 at 21:25
  • This can also happen when you have a previous branch, say AM-xxx/some_branch, and then create another one AM-XXX/another_branch, git will allow the differing cases locally and fail to pair the two remotely. – timpwbaker Jan 03 '18 at 10:54
  • Yes it is possible to _check out_ in the wrong mixed case but not _check in_ .. Just messy. – WestCoastProjects Jan 24 '19 at 00:43
30

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.

moggers
  • 503
  • 4
  • 8
  • 2
    this was my issue. I would suggest doing a quick `> git branch` and verify that your branch has a * next to it. – Andy Danger Gagne Jul 19 '18 at 13:21
  • This happened to me as well. @AndyDangerGagne, I'm glad you suggested this -- there was no * next to the branch that I was on, so I checked it out again, this time in lower case. – Cognitiaclaeves Jan 02 '19 at 21:31
  • I'm not exactly sure I understand what happened. I have a new branch that I couldn't push because of the same reason and thought I would try changing the first letter of the branch name to uppercase and it worked. I'm guessing the branch already existed and I didn't realize it, although i didn't see it. – Rich Sep 27 '21 at 15:40
13

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

Mahesh R
  • 131
  • 1
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Smit Gajera Dec 28 '21 at 12:33
12

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.

jojo
  • 569
  • 7
  • 7
11

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

JGL
  • 766
  • 1
  • 7
  • 16
11

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
Sher
  • 945
  • 1
  • 7
  • 7
5

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.

David
  • 11,245
  • 3
  • 41
  • 46
5

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
Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
Nervall
  • 225
  • 3
  • 7
3

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
Corbin Hudson
  • 176
  • 2
  • 8
3

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.

julianm
  • 2,393
  • 1
  • 23
  • 24
3

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

Shah
  • 2,126
  • 1
  • 16
  • 21
3

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.

Hui Li
  • 29
  • 3
2

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

joker
  • 3,416
  • 2
  • 34
  • 37
2

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.

Ivan Nieto
  • 21
  • 1
  • 1
2

I was having this issue as well with the branch named "bugFix/issue-2521", I realized that I already had the same branch name but without the capital letter "bugfix/issue-2521", I haven't faced conflict with creating this new branch however I facing issue when making upstreaming this branch. the simplest solution for this issue is to rename it git branch -m new-branch-name

Nazeh Taha
  • 65
  • 1
  • 6
1

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.

loko
  • 11
  • 2
1

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

ryzhman
  • 674
  • 10
  • 22
1

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.

Peter Boomsma
  • 8,851
  • 16
  • 93
  • 185
1

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!

1

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.

Luca Filip
  • 61
  • 5
1

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

David MD
  • 39
  • 3
1

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.

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
1

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

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

Suibur R.
  • 11
  • 1
1

Try re-name your branch if you have another branch which look alike.

I think GitHub file system is kind of struggling with same-like branch names if they're case sensitively different. In my case, I had a branch on the server like this,

Feature/Settings/Billing

then I was trying to publish another branch like this after awhile,

Feature/Settings/Billing-After-Revamp

then I got a fatal error like above, then I renamed the new branch as below,

Feature/Settings/After-Revamp-Billing

It worked like a charm and I was able to successfully publish my branch without fatal errors like above.

MrMalith
  • 1,352
  • 14
  • 22
0

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

Ronaldo Albertini
  • 1,329
  • 20
  • 24
0

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!

Community
  • 1
  • 1
KhogaEslam
  • 2,528
  • 1
  • 20
  • 21
0

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

Shayan Shafiq
  • 1,447
  • 5
  • 18
  • 25
Michael
  • 1,213
  • 6
  • 9
0

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.

bediV5
  • 38
  • 7
0

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
bigtheo
  • 624
  • 9
  • 16
0

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.

CodeSamurai
  • 623
  • 3
  • 6
0

Met this issue and resolved it with git branch --set-upstream-to=origin/<branch> main

Issa
  • 161
  • 1
  • 9
0

I just used lower case for the name of the branch and it worked

azizkale
  • 37
  • 2
  • 6