git TortoiseGit 克隆远程分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12709754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:43:14  来源:igfitidea点击:

TortoiseGit clone remote branch

gittortoisegit

提问by Thomas

I am trying to come to terms with Git as I recently started using it (long time Subversion user) and I cannot find a way to clone a remote branch with TortoiseGit.

我正在尝试接受 Git,因为我最近开始使用它(Subversion 的长期用户),但我找不到使用 TortoiseGit 克隆远程分支的方法。

I have created a local branch which I pushed to GitHub, but when I try to clone (checkout) this remote branch I cannot find any way to do it.

我创建了一个推送到 GitHub 的本地分支,但是当我尝试克隆(结帐)这个远程分支时,我找不到任何方法来做到这一点。

How can I do it?

我该怎么做?

回答by sbell

As stated by linquize, this functionality isn't directly provided by TortoiseGit. If you really want to use it though, you can:

正如 linquize 所说,这个功能不是由 TortoiseGit 直接提供的。如果你真的想使用它,你可以:

  • Clone the repository that the branch belongs to (right-click menu -> Git Clone...). This will also checkout the working copy created by clone to HEAD
  • 克隆分支所属的仓库(右键菜单 -> Git Clone...)。这也会将克隆创建的工作副本检出到 HEAD

TortoiseGit clone window

TortoiseGit 克隆窗口

  • Switch the working copy from HEAD to the desired branch/tag (right-click menu -> TortoiseGit -> Switch/Checkout)
  • 将工作副本从 HEAD 切换到所需的分支/标签(右键菜单 -> TortoiseGit -> Switch/Checkout)

TortoiseGit switch window

TortoiseGit 切换窗口

This will take a bit longer than from the command line, because the initial clone command implies a checkout to head, which you then have to switch back to the branch/tag you want.

这将比从命令行花费更长的时间,因为初始克隆命令意味着要结帐,然后您必须切换回所需的分支/标签。

回答by metaforge

(This is as of TortoiseGit v1.8.3.0.)

(这是从 TortoiseGit v1.8.3.0 开始的。)

Do a "Git -> Git Sync" first in the TortoiseGit context menu. (Note: you may have to hold Shiftdown as you right click, depending on how you have Git Sync set to show up in your context menu.)

首先在 TortoiseGit 上下文菜单中执行“Git -> Git Sync”。(注意:您可能需要在Shift右键单击时按住不放,具体取决于您将 Git Sync 设置为在上下文菜单中显示的方式。)

There will be a button in there at the bottom left called "Remote Update". Do that, and it will pull down all of the new remote branches that are not present in your local repository.

左下角会有一个名为“远程更新”的按钮。这样做,它将拉下本地存储库中不存在的所有新远程分支。

Remote Update

远程更新

After that, you should be able to do "Git -> Git Checkout" as normal, and the branch you want will show up in the list.

之后,您应该可以正常执行“Git -> Git Checkout”,并且您想要的分支将显示在列表中。

I should note that this same procedure can be used to inform TortoiseGit about new branches that have been created in the remote repository, whether you originally created them or not.

我应该注意,这个相同的过程可用于通知 TortoiseGit 有关在远程存储库中创建的新分支,无论您是否最初创建它们。

回答by Vishwajeet

It's available in Git clone window: enter image description here

它在 Git 克隆窗口中可用: 在此处输入图片说明

回答by Wendy William

Unfortunately, the current TortoiseGit (TortoiseGit 1.7.13.0) can not clone a specific branch. You may ask a feature request.

遗憾的是,目前的 TortoiseGit(TortoiseGit 1.7.13.0)无法克隆特定的分支。您可以询问功能请求。

The workaround:

解决方法:

  1. Use a manual Git command, e.g.: git clone --recursive --branch 2.x-1.0
  2. Use another Git GUI, e.g. SmartGit
  1. 使用手动 Git 命令,例如: git clone --recursive --branch 2.x-1.0
  2. 使用另一个 Git GUI,例如 SmartGit

Another way is to clone all branches then delete unwanted branches, but even this is not a good solution especially if you have many branches with many tags (and different file-names), but this is the workaround so far until TortoiseGit provides it. I choose to clone a branch manually using the command line. This question only happened for Windows users because the Git version of Linux already provides the --branchoptions.

另一种方法是克隆所有分支,然后删除不需要的分支,但即使这也不是一个好的解决方案,特别是如果您有许多带有许多标签(和不同文件名)的分支,但这是迄今为止 TortoiseGit 提供它之前的解决方法。我选择使用命令行手动克隆一个分支。这个问题只发生在 Windows 用户身上,因为 Linux 的 Git 版本已经提供了--branch选项。

回答by Martin Braun

Update regarding this:

关于此的更新:

If you only need a specific branch, you can SVN checkout it directly, nowadays. Copy the tree URL of the branch, i.e. https://github.com/USERNAME/REPONAME/tree/BRANCHNAMEand replace treewith branches, so you get https://github.com/USERNAME/REPONAME/branches/BRANCHNAME.

如果你只需要一个特定的分支,现在你可以直接 SVN 签出它。复制分支的树 URL,即https://github.com/USERNAME/REPONAME/tree/BRANCHNAME并替换treebranches,因此您得到https://github.com/USERNAME/REPONAME/branches/BRANCHNAME.

This URL can be used to checkout the specific branch.

此 URL 可用于检出特定分支。