How can I fetch an unmerged pull request for a branch I don't own?

后端 未结 13 1457
北荒
北荒 2020-11-27 10:55

I need to pull in a specific pull request (that hasn\'t been processed into the main stream yet) in the NServiceBus repo:

https://github.com/johnsimons/NServiceBus/c

相关标签:
13条回答
  • 2020-11-27 11:13
    git pull origin pull/28/head
    

    Or

    git fetch origin pull/28/head:28
    git checkout 28
    

    Can I pull a not-yet-merged pull request?

    0 讨论(0)
  • 2020-11-27 11:14

    To fetch a pull into your repository:

    git fetch git@github.com:jboss/jboss-common-beans.git refs/pull/4/head
    

    Then do whatever you want with FETCH_HEAD:

    git checkout -b new-branch FETCH_HEAD
    
    0 讨论(0)
  • 2020-11-27 11:15

    below is to make your 'git fetch' command to fetch all pull requests when run "git fetch"

    add below into ~/.gitconfig

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

    note the reference "refs/pull-requests/" has the stash naming convention, for git hub, you may need different format

    0 讨论(0)
  • 2020-11-27 11:17

    You can do this:

    1) Add the upstream remote:

    git remote add upstream git@github.com:Particular/NServiceBus.git
    

    2) After that, you can checkout any pull request to a new branch per its ID:

    git fetch upstream pull/PULL_REQUEST_ID/head:NEW_BRANCH_NAME
    

    Then you'll have a branch named NEW_BRANCH_NAME containing the PR code.

    Adding an alias:

    If you do this as often as me, you may want to setup some aliases for it. I have this in my .gitconfig:

    [alias]
        fetch-pr = "!f(){\
            [ -z \"$1\" ] && { echo Usage: git fetch-pr PULL_REQUEST_ID [REMOTE_NAME] [NEW_BRANCH_NAME]; exit 1; }; \
            remote=${2:-origin}; \
            branch=${3:-pr-$1}; \
            git fetch $remote \"pull/$1/head:$branch\"; \
            }; f "
        pr = "!f(){\
            branch=${3:-pr-$1}; \
            git fetch-pr \"$@\"; \
            git switch $branch; \
            }; f "
    

    With the above, I can do:

    git fetch-pr 123              # fetch PR #123 into branch pr-123
    git fetch-pr 123 some-branch  # fetch PR #123 into some-branch
    git pr 123                    # fetch and switch to the branch
    
    0 讨论(0)
  • 2020-11-27 11:20

    This is the solution from GitHub docs:

    From your project repository, check out a new branch and test the changes.

    git checkout -b GithubUserID-branchName branchName
    git pull https://github.com/GithubUserID/reponame.git branchName
    

    Where:

    1. GithubUserID is the username of the person who opened the pull request.
    2. branchName is the name of the branch for example master
    3. reponame the repository name like demo-todo

    Example :

    git checkout -b felix123-master master
    git pull https://github.com/felix123/demo-todo.git master
    
    0 讨论(0)
  • 2020-11-27 11:22

    See this help article from GitHub: https://help.github.com/articles/checking-out-pull-requests-locally

    0 讨论(0)
提交回复
热议问题