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

git push origin branch-name

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

git pull origin branch-name

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

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


当前回答

你可以像这样使用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克隆(源地址)(分支名称)

导航到新机器上你想要从git上的git bash下载的文件夹。

使用下面的命令从您喜欢的任何分支下载代码

git clone 'git ssh url'

它将下载相应的分支代码。

你可以像这样使用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]

在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