27

When I do a git status, I get my branch:

$ git status
On branch OfflineLoading

When I tried to git push, I get:

$ git push origin OfflineLoading
fatal: OfflineLoading cannot be resolved to branch.

When I check the branches, it is not there:

$ git branch
   branch1
   branch2
   branch3
   branch4

How do I fix this?

k0pernikus
  • 60,309
  • 67
  • 216
  • 347
Matt Kuhns
  • 1,328
  • 1
  • 13
  • 26
  • Did you create and changed your work to your new branch? This can be helpful: http://stackoverflow.com/questions/11860362/git-master-cannot-be-resolved-to-branch-after-merge – Hime Jul 22 '16 at 19:02
  • 1
    I guess you might be doing some spelling mistake / case mistake. Ideally, it should make the remote branch if it doesn't exist or push to remote branch if it exists. Your command seems correct – Pankaj Singhal Jul 22 '16 at 19:05
  • I checked the spelling and it is right. Do I need to set upstream? – Matt Kuhns Jul 22 '16 at 19:13
  • 1
    can you post the output of `git show-ref | grep -i OfflineLoading` – Yuri G. Jul 22 '16 at 20:33
  • Is the local branch tracking the upstream one? – k0pernikus Jul 22 '16 at 22:18
  • 1
    How did you create this branch `OfflineLoading`? Specifically, *did you use `git checkout --orphan`?* If so, that's the problem: orphan branches aren't actually created until you commit something into them. If not, something is seriously wrong on your computer / in your repository. – torek Jul 23 '16 at 00:34
  • Also please share what version of git, operating system, and if/what git GUI you're using. – Jeff Puckett Jul 23 '16 at 00:34
  • Thanks for all the responses. I just bit the bullet and saved off my repo and cloned again. Then I overlayed files with my saved directory. Not elegant, but did the trick. – Matt Kuhns Jul 25 '16 at 16:13
  • most of the time it changes the first letter with caps , you try by doing ``` git branch``` and search your branch and then checkout that branch and then do the ```git push``` – shashikant kuswaha Apr 07 '21 at 12:29

9 Answers9

39

The common issue is case mistake. I got the same issue before. The better way to do it is to check what are the branch names:

$ git branch
  master
 *branch1
  Branch2

you can compare the branch on above, then push it with the name you got.

$ git push origin Branch2

or

$ git push origin branch1
Kyle
  • 399
  • 3
  • 4
10

In addition to Kyle's answer,

In cases where you already have a branch name like "BugFix/item001" and pushed it to your repository, and then you created another branch with the name "Bugfix/item002", you will still get the same error even if you try to push the branch with the correct casing. I believe this is because of the "BugFix" folder being created already and future branches will use the same folder.

It is still a casing mistake but really misleading.

Sueii
  • 101
  • 1
  • 4
3

My branch name was feature/S212121_TestCase_review_Dashboard

When I try to push code to this branch feature/S212121_TestCase_review_Dashboard by using following command:

git push origin feature/S212121_TestCase_review_Dashboard
fatal: feature/S212121_TestCase_review_Dashboard cannot be resolved to branch

Then I have renamed the my branch using following command:

git branch -m TestCase_review_CWLA_Dashboard

After that I have used following command to push the code:

git push --set-upstream origin TestCase_review_CWLA_Dashboard

This works for me I am able to push the code to branch.

Pierre.Vriens
  • 2,117
  • 75
  • 29
  • 42
Chinya
  • 41
  • 3
1

Sometimes this happens when you mistakenly checked out a wrong branch, do a commit on the same wrong branch and then do a push. On my case I had a branch called questionbank and made a mistake of checking out questionBank (note with capital 'B'), then I did a commit and git allowed it all up to a point when I wanted to do a push.

Solution was to checkout the correct branch (which on my case was "questionbank"), do some change on the code ( just for git to allow you to commit) then do a commit and then the push will work just fine.

user2968230
  • 174
  • 2
  • 7
1

This happens when you have any capital letter in your branch name because the branch names are case sensitive. So go to .git-> refs-> heads then you can see your branches, remove the capital letter from your current branch name and that's it.

1

It might be because you are not in the latest master branch.

For this you could check with terminal commands on the master branch:

git pull  

or

git pull origin (master branch)

and checked your branch.

I created a new branch

git checkout -b newbranch 

and pushed to a new branch from the old branch that "has cannot be resolved" error using:

git push origin newbranch 

This worked for me.

Xab Ion
  • 1,105
  • 1
  • 11
  • 20
0

Checking out to a new branch and pushing it again works for me. git checkout -b 2020-08-05/OfflineLoading git push

Jun Yin
  • 2,019
  • 3
  • 16
  • 18
0

I had to make a small change and add my commit again then push and it worked!

  • 1
    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). – Community Jan 06 '22 at 23:25
0

Not an ideal solution, but worked for me :

Checkout to different branch (let's say eg: 'branch2') & again checkout back to your feature branch and try to push to remote.