Clone from a branch other than master

大憨熊 提交于 2020-06-09 07:33:45

问题


I am trying to pull from a repository in Github. But I don't want to clone the master branch. I want to clone some other branch. When I try git clone <url>, I get the files from master branch. What should I do?

Also, suppose the code is updated in the repository and I want to get the latest code, should I again use git clone? Because the size of the project is huge. Also if I make changes to the project locally, and then I again use git clone, will the changes I made still be there? What if I don't want changes to be there?

I am not even sure if git clone is the right command. git pull or git fetch?

I am sorry, I am very new to git.


回答1:


Try this:

git init
git fetch url-to-repo branchname:refs/remotes/origin/branchname

EDIT

A better solution:

git clone -b mybranch --single-branch git://sub.domain.com/repo.git



回答2:


git clone <url>

clones and creates remote-tracking branches for each branch. If you want to see available branches (after cloning), you type

git branch -l

To switch to a particular branch after cloning you do:

git checkout <branchname>

where branchname is the name of the branch :)

If you want to clone and checkout a specific branch you do

git clone -b <branchname> <url>

The other commands you mention are for "updating" your current working copy. git pull gets all changes from the remote repository and merges them while git fetchonly gets them without merging.




回答3:


use git clone --branch <name> possibly adding --single-branch

as usual you have git clone --help to read details on commands



来源:https://stackoverflow.com/questions/17383217/clone-from-a-branch-other-than-master

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!