别人fork我的repo,然后给我提交pr:others_name:master → origin:master
# 查看本地仓库的remote anny@annys-MacBook-Air djwcb % git remote -v origin https://github.com/GZhonghui/djwcb.git (fetch) origin https://github.com/GZhonghui/djwcb.git (push) # 添加remote # <typenoob>这个是随便取的名字,能区分开就OK,建议使用对方的用户名 anny@annys-MacBook-Air djwcb % git remote add typenoob https://github.com/typenoob/djwcb.git anny@annys-MacBook-Air djwcb % git remote -v origin https://github.com/GZhonghui/djwcb.git (fetch) origin https://github.com/GZhonghui/djwcb.git (push) typenoob https://github.com/typenoob/djwcb.git (fetch) typenoob https://github.com/typenoob/djwcb.git (push) # 删除remote anny@annys-MacBook-Air djwcb % git remote -v origin https://github.com/GZhonghui/djwcb.git (fetch) origin https://github.com/GZhonghui/djwcb.git (push) typenoob https://github.com/typenoob/djwcb.git (fetch) typenoob https://github.com/typenoob/djwcb.git (push) anny@annys-MacBook-Air djwcb % git remote remove typenoob anny@annys-MacBook-Air djwcb % git remote -v origin https://github.com/GZhonghui/djwcb.git (fetch) origin https://github.com/GZhonghui/djwcb.git (push) # 拉一个pr到本地,本地分支叫pr-1(1是pr的ID) anny@annys-MacBook-Air djwcb % git fetch origin pull/1/head:pr-1 remote: Enumerating objects: 40, done. remote: Counting objects: 100% (34/34), done. remote: Compressing objects: 100% (8/8), done. remote: Total 24 (delta 16), reused 24 (delta 16), pack-reused 0 (from 0) Unpacking objects: 100% (24/24), 2.99 KiB | 127.00 KiB/s, done. From https://github.com/GZhonghui/djwcb * [new ref] refs/pull/1/head -> pr-1 anny@annys-MacBook-Air djwcb % git checkout pr-1 Switched to branch 'pr-1' # 也可以把对方的分支都fetch下来 anny@annys-MacBook-Air djwcb % git fetch typenoob From https://github.com/typenoob/djwcb * [new branch] add-search-bar -> typenoob/add-search-bar * [new branch] master -> typenoob/master # 然后在这个pr-1上测试 # 注意:这个pr-1只是个本地测试分支,一般不需要push到服务器
需要安装GitHub CLI
如果对方的PR没有什么大问题,但是需要一些小修改,可以:
# 使用Github CLI # 需要Token anny@annys-MacBook-Air djwcb % export GH_TOKEN=xxx # 直接checkout到pr anny@annys-MacBook-Air djwcb % gh pr checkout 1 From https://github.com/GZhonghui/djwcb * [new ref] refs/pull/1/head -> typenoob/master Switched to branch 'typenoob/master' # 修改,添加commit # 推送到对方的master(提出合并的分支)!居然可以这样做的嘛 git push https://github.com/typenoob/djwcb.git HEAD:master # 然后在Github的网页上,就可以看到PR更新了(自己增加了commit) # 错误示范:使用git推送一个pr-1的分支 # 这会在服务器上创建一个新的分支pr-1,但是和对方的pr没有绑定关系 anny@annys-MacBook-Air djwcb % git push origin pr-1 Enumerating objects: 49, done. Counting objects: 100% (41/41), done. Delta compression using up to 8 threads Compressing objects: 100% (29/29), done. Writing objects: 100% (29/29), 3.64 KiB | 3.64 MiB/s, done. Total 29 (delta 20), reused 0 (delta 0), pack-reused 0 (from 0) remote: Resolving deltas: 100% (20/20), completed with 8 local objects. remote: remote: Create a pull request for 'pr-1' on GitHub by visiting: remote: https://github.com/GZhonghui/djwcb/pull/new/pr-1 remote: To https://github.com/GZhonghui/djwcb.git * [new branch] pr-1 -> pr-1