Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning a branch : Remote branch branch-99 not found in upstream origin [duplicate]

Tags:

How can I clone a branch from git with a specific Branch name?

I have a branch named branch-99 and my user name is Istiak.

I try to clone my branch like:

git clone -b branch-99 [email protected]/admin.git 

I am receiving this error.

fatal: Remote branch branch-99 not found in upstream origin

What I am doing wrong here?

like image 379
Istiak Mahmood Avatar asked Sep 15 '15 05:09

Istiak Mahmood


People also ask

How do I clone a specific branch from a remote?

You can clone a specific branch from a Git repository using the git clone –single-branch –branch command. This command retrieves all the files and metadata associated with one branch. To retrieve other branches, you'll need to fetch them later on.

How do you solve the current branch has no upstream branch?

Fatal Git Error: Current branch has no upstream The simple solution to the current problem is easily solved by issuing the following Git push upstream command: git@upstream-error /c/branch/push (new-branch) $ git push --set-upstream origin new-branch Enumerating objects: 3, done.

What does it mean if a branch has no upstream branch?

The fatal: The current branch master has no upstream branch error occurs when you have not configured git in such a way that it creates a new branch on the remote. Therefore, you are only creating a new branch on the local computer.

How do I duplicate a branch in GitHub?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'...


2 Answers

branch-99 does not exist on the remote repository. You probably misspelled the branch name or the repository.

To check which branches exist, use ls-remote. You can use it on the remote...

git ls-remote --heads origin 

Or if you haven't already cloned the repository, on a URL.

git ls-remote --heads [email protected]:Christoffer/admin.git 

You'll get the commit IDs and branch names, but they'll be full references like refs/heads/<branch>.

8c2ac78ceba9c5265daeab1519b84664127c0e7d    refs/heads/fix/that 6bc88ec7c9c7ce680f8d69ced2e09f18c1747393    refs/heads/master 83f062226716bb9cebf10779834db1ace5578c50    refs/heads/branch-42 

See gitrevisions for more.


To be clear, git clone -b branch-99 [email protected]:Christoffer/admin.git clones the entire repository. It just checks out branch-99 rather than master. It's the same as...

git clone [email protected]:Christoffer/admin.git git checkout branch-99 

That bit of syntax sugar isn't worth the bother. I guess it might save you a tiny bit of time not having to checkout master.

If you want to clone just the history of one branch to save some network and disk space use --single-branch.

git clone --single-branch -b branch-99 [email protected]:Christoffer/admin.git 

However it's usually not worth the trouble. Git is very disk and network efficient. And the whole history of that branch has to be cloned which usually includes most of the repository anyway.

like image 179
Schwern Avatar answered Sep 19 '22 12:09

Schwern


git clone [email protected]:Christoffer/admin.git git checkout branch-99 
like image 41
Zepplock Avatar answered Sep 18 '22 12:09

Zepplock