Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
签出本地不存在的远程git分支?_Git_Branch - Fatal编程技术网

签出本地不存在的远程git分支?

签出本地不存在的远程git分支?,git,branch,Git,Branch,假设我的本地存储库是从同一个git存储库克隆而来的,该存储库有一个远程克隆,而我的克隆中没有该远程克隆上的一个分支(不是默认分支) 有没有办法将远程分支克隆到我的本地副本中?我不想将它与当前分支或类似的东西合并。我只想启动远程分支的本地副本。有办法做到这一点吗 我还想知道(完成后)如何将提到的分支也添加到默认情况下本地克隆签入的默认远程副本中。您需要运行以下操作: # Fetch everything from the other remote git fetch <remote name

假设我的本地存储库是从同一个git存储库克隆而来的,该存储库有一个远程克隆,而我的克隆中没有该远程克隆上的一个分支(不是默认分支)

有没有办法将远程分支克隆到我的本地副本中?我不想将它与当前分支或类似的东西合并。我只想启动远程分支的本地副本。有办法做到这一点吗


我还想知道(完成后)如何将提到的分支也添加到默认情况下本地克隆签入的默认远程副本中。

您需要运行以下操作:

# Fetch everything from the other remote
git fetch <remote name>
# Check out the remote version of the branch
git checkout <remote name>/<branch name>
# Create the new local branch
git checkout -b <branch name>
这将把新的分支推到原来的遥控器上。

只需使用下一步:

git fetch <remote repo name>
git checkout -b <local branch name> <remote repo name>/<remote branch name>
git-fetch
git签出-b/

这对我的情况很有帮助,并且此过程与通过我的Windows机器上的TortoiseGit自动生成的操作相同。

一个命令将完成此工作:

git checkout -b <local_branch_name> origin/<remote_branch_name>
git签出-b源/
编辑: 如果发生错误: 致命:“origin/”不是提交,无法从中创建分支“”

你可以尝试:

git pull
git checkout -b <local_branch_name> origin/<remote_branch_name>
git拉
git签出-b源/

我不确定我是否明白。你的指示中有我不明白的地方。如果你看看这个垃圾桶,也许你可以告诉我我做错了什么,我误解了你的建议。啊,是的,好的。首先使用
git remote add
,然后使用您提供的远程名称获取。这样,您以后也可以轻松地从该存储库获取后续更改。如果您不想这样做,
git fetch
然后
git checkout fetch\u HEAD
应该做您想做的事情,但是您需要知道另一个远程上的分支的名称。是否总是需要git fetch?@KonradViltersten是的
git pull
git checkout -b <local_branch_name> origin/<remote_branch_name>