简体   繁体   English

如何制作远程git分支的副本(不与我现有的分支合并)?

[英]How to make a copy of a remote git branch (without merging with my existing branch)?

Suppose that I have been working on a git repo and the branch I'm working on is called MyBranch . 假设我一直在处理一个git repo ,而我正在研究的分支叫做MyBranch

My co-worker tells me that he has something that I should pull from his branch on his git repo . 我的同事告诉我,他有一些东西,我应该从他的分支机构中取出他的git repo His branch is called HisBranch . 他的分支被称为HisBranch

In order to do this, I type 为了做到这一点,我打字

git remote add MyCoworker $url
git checkout -b HisBranch
git pull MyCoworker HisBranch

When I do the git pull, it tells me that it is fetching data from the remote repo as intended, but since I created HisBranch locally by branching from MyBranch , it contains the same files and history as MyBranch , and git wants to merge the two together. 当我做的git拉,它告诉我,这是从远程获取数据repo的预期,但由于我创建HisBranch本地由分支MyBranch ,它包含相同的文件和历史MyBranch ,和git要合并两个一起。

What I really want is to get a branch on my local repo that is identical to what I pulled from my co-workers branch, including the history. 我真正想要的是在我的本地repo建立一个与我从同事分支机构中获取的分支相同的分支,包括历史记录。 I do not wish to immediately merge it with my own branch. 我不希望立即将它与我自己的分支合并。

$ git remote add MyCoworker $url
$ git fetch MyCoworker

It'll show sth like 它会表现得像

... ...
* [new branch] HisBranch -> MyCoworker/HisBranch * [新分支] HisBranch - > MyCoworker / HisBranch

then u can just check to his branch correctly: 然后你可以正确检查他的分支:

$ git checkout HisBranch

Btw, if ur repo is the main repo to work on (ur co-work forks it to his own), then u need to ask him to send a Pull Request (aka PR) to u instead. 顺便说一句,如果你的回购是主要的回购工作(你的合作工作是他自己的),那么你需要让他向你发送一个拉请求(又名PR)。

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

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