我有一个项目托管在GitHub上。我在一台计算机上创建了一个分支,然后将我的更改推到GitHub:
git push origin branch-name
现在我在另一台计算机上,我想下载那个分支。所以我试着:
git pull origin branch-name
...但这一切都是覆盖我的主分支与我的新分支的变化。
我需要做什么才能正确地拉出我的远程分支,而不覆盖现有的分支?
我有一个项目托管在GitHub上。我在一台计算机上创建了一个分支,然后将我的更改推到GitHub:
git push origin branch-name
现在我在另一台计算机上,我想下载那个分支。所以我试着:
git pull origin branch-name
...但这一切都是覆盖我的主分支与我的新分支的变化。
我需要做什么才能正确地拉出我的远程分支,而不覆盖现有的分支?
当前回答
我们可以使用以下神奇的命令来下载指定的分支:
git clone -b < branch name > <remote_repo url>
其他回答
导航到新机器上你想要从git上的git bash下载的文件夹。
使用下面的命令从您喜欢的任何分支下载代码
git clone 'git ssh url'
它将下载相应的分支代码。
$ git fetch
$ git checkout <分支>
Git fetch将获取所有远程分支。 您可以使用git branch -r(或git branch -rv)来验证远程分支。 如果你没有同名的分支,你可以使用git checkout <branch>直接切换到这个分支
对于像我这样的Git新手,可以按照以下步骤下载远程存储库,然后切换到想要查看的分支。他们可能在某种程度上滥用Git,但它对我有用!: -)
克隆你想要下载代码的存储库(在这个例子中,我选择了Github上的LRResty项目):
$ git clone https://github.com/lukeredpath/LRResty.git
$ cd LRResty
检查你正在使用的分支(应该是主分支):
$ git branch
* master
查看你想要的分支,在我的情况下,它被称为“arcified”:
$ git checkout -b arcified origin/arcified
Branch arcified set up to track remote branch arcified from origin.
Switched to a new branch 'arcified'
确认你现在正在使用你想要的分支:
$ git branch
* arcified
master
如果你想稍后再次更新代码,运行git pull:
$ git pull
Already up-to-date.
在repo名称中复制Git和cd:
$ git clone https://github.com/PabloEzequiel/iOS-AppleWach.git
Cloning into 'iOS-AppleWach'...
$ cd iOS-AppleWach
切换到我想要的分支(GitHub页面):
$ git checkout -b gh-pages origin/gh-pages
Branch gh-pages set up to track remote branch gh-pages from origin.
Switched to a new branch 'gh-pages'
拉树枝:
$ git pull
Already up-to-date.
ls:
$ ls
index.html params.json stylesheets
Git checkout -b branch/name
Git拉源码分支/名称