我有一个项目托管在GitHub上。我在一台计算机上创建了一个分支,然后将我的更改推到GitHub:

git push origin branch-name

现在我在另一台计算机上,我想下载那个分支。所以我试着:

git pull origin branch-name

...但这一切都是覆盖我的主分支与我的新分支的变化。

我需要做什么才能正确地拉出我的远程分支,而不覆盖现有的分支?


当前回答

对于像我这样的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.

其他回答

Git checkout -b branch/name

Git拉源码分支/名称

创建一个新目录,然后做一个克隆。

Git克隆(源地址)(分支名称)

你可以像这样使用git远程:

git fetch origin

然后设置一个本地分支来跟踪远程分支,如下所示:

git branch --track [local-branch-name] origin/remote-branch-name

现在远程github分支的内容在local-branch-name中。

你可以切换到local-branch-name并开始工作:

git checkout [local-branch-name]

快速回答:

https://github.com/[username]/[respository]/archive/refs/heads/[branch].zip

您可以使用该链接直接下载,而无需使用复杂的cmd。

$ git fetch

$ git checkout <分支>

Git fetch将获取所有远程分支。 您可以使用git branch -r(或git branch -rv)来验证远程分支。 如果你没有同名的分支,你可以使用git checkout <branch>直接切换到这个分支