Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git error "fatal: XXX is not a commit and a branch YYY cannot be created from it

Tags:

git

github

I am trying the checkout a branch from a remote repository into a local branch, and receive the above error.

For those who want to direct me to: Why is it not a commit and a branch cannot be created from it?, then I already tried fetching, and even git fetch --all

To be precise, I cannot checkout any branch on the Github repository, that is not the main branch that I'm tracking, let's call it dev.

So, I can do the following:

git checkout origin/dev -b my_own_dev_env

But I cannot checkout any other branch, not even

git checkout origin/master -b master

And in this case I receive

"fatal: 'origin/master' is not a commit and a branch 'master' cannot be created from it"

Edit: When cloning to a new directory, I can perform all git operations as usual. So I would like to know what could go wrong in a local copy that prevents git commands from working properly?

like image 736
Investing TS Avatar asked Aug 07 '19 07:08

Investing TS


1 Answers

First check whether you have fetched all branches or not by executing following command.

git fetch --all

Check for existence of branch name in local

git branch -a

Execute command to track remote branch and create one in local

git checkout -t origin/<Branch Name>
like image 66
Sohan Kumar Avatar answered Sep 27 '22 01:09

Sohan Kumar