How to create a copy of a branch from a remote repository?
- A good git doc is called by git help and then for example git help checkout and where is the second question? - zb '
- I haven't figured it out yet, but it will be soon - noskovgleb
- Who modeled the question? Do you know Russian ? - zb '
|
3 answers
This command will create a local copy of the remote branch.
git checkout -b remote_branch origin/remote_branch
- Does it not copy a branch of an existing repository just as a remote option? - Aios
- In my opinion, this is what the forger wanted to achieve, or did I misunderstand the question? - AlexDenisov
- The fact is that if you are guided by your team, then the original branch is cloned from the remote with the git checkout branch command, if you have to create the branch yourself, then you need to create it on the remote host and from the remote one anyway, take the branch below .. for origin is the one that is repo in general ... maybe I misunderstood the question ... - Aios
- oneI did not understand your last comment at all, sorry. - AlexDenisov
|
Modern versions of Git make it much easier to do this:
git checkout branchname
It works when:
- There is a remote
origin/branchname
- But there is no local branch named
branchname
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'
Checking:
$ 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?
|