如何使用git合并特定的分支?

Bas*_*asj 2 git github

注意:这与此问题有某种联系,但它需要额外关注分支.

假设我有一个Github项目https://github.com/basjj/myproject.git ,我的计算机上有2个分支(masterfeature1)和一个本地存储库.

名为的用户blah提出了一个pull-request.他有3个分支(master,feature1,feature2)上https://github.com/blah/myproject.git.

情况1

我想feature2在我的计算机上尝试他的分支,稍微修改它,并将其合并到我自己的master.以下命令是否正确?

git checkout -b feature2
git pull https://github.com/blah/myproject.git   # it pulls only his feature2 branch or all?
# review the new files, make changes, etc.
git add .
git commit
git checkout master
git merge feature2
Run Code Online (Sandbox Code Playgroud)

第二行(git pull...)是拉他所有的分支还是仅仅是他的feature2
还有别的:用户是否blah会出现在Github的贡献者列表中

案例#2

我想feature1在我的计算机上尝试他的分支,稍微修改它,并将其合并到我自己的master.怎么做,鉴于我feature1自己已经有一个分支,我不想覆盖(!)?

Von*_*onC 6

根据远程名称,所有分支都在自己的命名空间中.

因此,最好为要试用的仓库添加一个遥控器:

git remote add blah https://github.com/blah/myproject.git
Run Code Online (Sandbox Code Playgroud)

然后你可以从blah取

git fetch blah
Run Code Online (Sandbox Code Playgroud)

并创建你feature2blah/feature2:

git checkout -b feature2 blah/feature2
Run Code Online (Sandbox Code Playgroud)

至于feature1,您可以简单地合并blah/feature1到您的master.
或者您可以创建自己的本地分支:

git checkout -b blah_feature1 blah/feature1
Run Code Online (Sandbox Code Playgroud)