简体   繁体   English

Git将远程分支提取到新的本地分支(使用一个命令)

[英]Git fetch remote branch into new local branch (with one command)

I have my local repo with *master tracking remote A's *master. 我有我的本地回购与* master跟踪远程A的*主人。 (Remote A's *master is its only active branch.) (Remote A的* master是它唯一的活动分支。)

Remote B now has a *prbranch that has some extra work not in A/master. 远程B现在有一个* prbranch,有一些额外的工作不在A / master中。 My local repo doesn't have any reference to any remote besides A (and my personal remote that is only used for pushing). 我的本地仓库除了A(以及我用于推送的个人遥控器)之外没有任何遥控器的参考。

How can I a) fetch B/prbranch into my local repo and b) create a new local branch with the same name and changes automatically? 我怎样才能a)将B / prbranch提取到我的本地仓库中并且b)创建一个具有相同名称的新本地分支并自动更改?

git fetch B prbranch correctly fetches the branch, but puts it into FETCH_HEAD with which I have to manually create a like-named branch. git fetch B prbranch正确地获取分支,但是将它放入FETCH_HEAD中,我必须手动创建一个类似命名的分支。

git pull B prbranch is of course useless, trying to merge into the current local branch git pull B prbranch当然没用,试图合并到当前的本地分支

and git clone --single-branch B prbranch just makes a new repo in a subfolder of the current repo. git clone --single-branch B prbranch只是在当前git clone --single-branch B prbranch的子文件夹中创建一个新的git clone --single-branch B prbranch

So how can I fetch the remote branch AND create an identical local branch in one command? 那么如何获取远程分支并在一个命令中创建一个相同的本地分支? Surely this isn't hard to do... 当然这不难做到......

(My experience is of course limited, so I expect that the answer will be simple and "retroactively obvious".) (我的经验当然是有限的,所以我希望答案很简单,“追溯显而易见”。)

The following command will fetch and create a local branch without creating a remote tracking branch: 以下命令将获取并创建本地分支,而不创建远程跟踪分支:

git fetch <urlB> refs/heads/prbranch:refs/heads/prbranch

See Git Internals - The Refspec on the documentation. 请参阅文档中的Git Internals - Refspec

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM