Checkout bitbucket pull requests locally

后端 未结 9 518
再見小時候
再見小時候 2020-12-08 02:48

I found this gist, showing how to check out a pull request locally from GitHub.

I\'m using bitbucket and I\'m looking for a similar function.

Can you help m

9条回答
  •  青春惊慌失措
    2020-12-08 03:07

    Fetch/Checkout Pull Requests

    This works for bitbucket. Other server could have different refs: (refspecs) or no refs: at all.

    First Time

    First of all you need to add the pull request refs: of the remote repository. To do that to a repository (e.g. aliased 'upstream'):

    git config --add remote.upstream.fetch '+refs/pull-requests/*/from:refs/remotes/upstream/pull-requests/*'
    

    That is, you add the last line on git .config file:

    [remote "origin"]
       url = ssh://git@git.blablabla.net/~user/repository.git
       fetch = +refs/heads/*:refs/remotes/origin/*
       fetch = +refs/pull/*/head:refs/remotes/origin/pull-requests/*
    

    Fetching

    Then if you perform the remote fetch you should see the retrieval of (also) all the pull requests:

    git fetch upstream
    
    From ssh://git.blablabla.net/somepath/repository
     * [new ref]         refs/pull-requests/1188/from -> upstream/pull-requests/1188
     * [new ref]         refs/pull-requests/1741/from -> upstream/pull-requests/1741
     * [new ref]         refs/pull-requests/2394/from -> upstream/pull-requests/2394
    

    Checking out

    Finally you can checkout the pull-request you prefer:

    git checkout pull-requests/2723
    

    Successfully tested on dedicated bitbucket server 27/02/19.

提交回复
热议问题