Matt Kuhns
Matt Kuhns

Reputation: 1368

How to fix "cannot be resolved to branch" on git push?

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?

Upvotes: 28

Views: 64412

Answers (9)

Shishir Aithal
Shishir Aithal

Reputation: 122

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.

Upvotes: 0

alishasapkota
alishasapkota

Reputation: 11

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.

Upvotes: 1

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

Upvotes: 0

Chinya
Chinya

Reputation: 51

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.

Upvotes: 4

Rezwan Ibnee Mohsin
Rezwan Ibnee Mohsin

Reputation: 31

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.

Upvotes: 1

user2968230
user2968230

Reputation: 174

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.

Upvotes: 1

Jun Yin
Jun Yin

Reputation: 2419

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

Upvotes: 0

Sueii
Sueii

Reputation: 111

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.

Upvotes: 11

Kyle
Kyle

Reputation: 399

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

Upvotes: 39

Related Questions