How to create a copy of a branch from a remote repository?
This command will create a local copy of the remote branch.
git checkout -b remote_branch origin/remote_branch
Modern versions of Git make it much easier to do this:
git checkout branchname
It works when:
- There is a remote
- But there is no local branch named
Suppose there is a remote branch
feature , which you do not already have locally.
$ git branch --all * master remotes/origin/HEAD -> origin/master remotes/origin/feature remotes/origin/master
Enough of this:
$ git checkout feature Branch feature set up to track remote branch feature from origin. Switched to a new branch 'feature'
$ git branch --all * feature master remotes/origin/HEAD -> origin/master remotes/origin/feature remotes/origin/master
The new branch really keeps track of the remote:
git branch -vv * feature ed185c8 [origin/feature] extract environment master 4db6d3b [origin/master] stylecheck-driven syntax improvements
git remote add workflow git://github.com/someuser/somerepo.git git fetch workflow git checkout -b remote_branch workflow/somebranch
Is it less suitable for remotely other non-repository and creating one of its branches as a separate branch in your repo?