2017-02-10 40 views
3

我们有两名学生从我们的在线存储库(不同的repo)开始工作,这个存储库从一个共同的上游回购协议中分离出来。Git从别人的叉子上拉下来

假设其他学生在特定的分支上做了变更,提交和推送到他的回购。

  1. 如何将这些更改引入我自己的本地存储库?

  2. 我是否需要提交并将这些更改推送到演示区域?

谢谢!

回答

0

提交并推送您的工作分支。然后从主分支合并到你的分支。确保所有构建和解决任何冲突。提交并推送你的分支。现在将你的分支合并到主分支中,它应该可以工作。

8

只需在您的own回购中添加新的远程设备(例如,other)。然后将other/<branch>更改为您的本地分支(例如,add-other-changes)。推到你自己的分叉回购(origin/add-other-changes)。现在,当您完成add-other-changes分支时,创建拉取请求&与origin/master合并。

  • 拉其他回购的变成自己的回购协议:

    # go into your own repo 
    $ git remote add other <other-student-repo-url> # add a new remote with other's repo URL 
    
    $ git fetch other  # sync/update local with other's repo 
    
    $ git checkout -b add-other-changes  # create a new branch named 'add-other-changes'      
    $ git pull other <specific-branch-name> # pull other/<branch> changes   
    
    $ git push origin HEAD # push changes to your own(origin) forked repo `add-other-changes` branch 
    
+0

完美!谢谢:) –

+0

现在完成了,如何跟踪其他学生的变化? –

+0

'git fetch other'会更新您的本地并与​​其他学生的回购更改。如果你需要任何特定的分支变化,那么就把它拉到'git pull other '。 –

0

如果你既想在同一项目上工作,那么你不应该两次分叉的存储库。你或你的朋友(不是两个)应该分派存储库,那么你们都应该在本地克隆分叉的(权限需要由分叉存储库的人授予)。

完成此操作后,当项目成员想要知道远程设备上是否有新的更改时,他们可以执行git remote update或更常见的git fetch origin

如果你工作在同一分支上,你想用遥控一个git pull origin <branh_name>

更新本地分支如果一个人已经提出,应该得到共享的变化:

git add file_path_1 file_path_2 directory_path1 ... 
git commit -m "<your brief message>" 
git push origin <branch_name>