What is the correct git config for working with GitHub pull requests?

前端 未结 4 2425
情话喂你
情话喂你 2021-02-18 21:44

I\'m aware of How can I check out a GitHub pull request?

While adding fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to .git/config does al

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-18 22:22

    From the fetch specs is not possible to find unambiguously find that remote reference refs/remotes/origin/pr/123 tracks origin:refs/pull/123/head because origin:refs/heads/pr/123 is also possible. To help it, you could use different remote name for example:

    [remote "origin-pr"]
      url = 
      fetch = +refs/pull/*/head:refs/remotes/origin-pr/pr/*
    

    Then git checkout with explicit branch name (which should be available in GUIs) would be able to create correct tracking reference:

    $ git checkout -b pr/123 origin-pr/pr/123
    
    [branch "pr/123"]
     remote = origin-pr
     merge = refs/pull/123/head
    

    Though, looks like it is not possible to make simple git checkout br/123 work:

    $ git checkout pr/123                         
    error: pathspec 'pr/123' did not match any file(s) known to git.
    

提交回复
热议问题