Let's say there is a remote clone of the same git repository that my local repository is cloned from - and there is a branch on that remote clone that isn't present in my clone (not the default branch).
Is there a way to clone that remote branch into my local copy? I don't want to merge it with the current branch or anything like that. I just want to start a local copy of the remote branch. Is there a way to do this?
I would also like to know (once this is done) how to add the mentioned branch also to the default remote-copy that my local clone checks in with by default.
Just use next:
git fetch <remote repo name>
git checkout -b <local branch name> <remote repo name>/<remote branch name>
It was helpful in my case and this procedure is identical to automatically generated action through TortoiseGit on my Windows machine.
One command will do this work:
git checkout -b <local_branch_name> origin/<remote_branch_name>
Edit: If an error occurred: fatal: 'origin/<branch_name>' is not a commit and a branch '<branch_name>' cannot be created from it.
You may try:
git pull
git checkout -b <local_branch_name> origin/<remote_branch_name>
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