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?
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.
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.
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.
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'...
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.
git clone [email protected]:Christoffer/admin.git git checkout branch-99
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With