How to apply unmerged upstream pull requests from other forks into my fork?

后端 未结 7 1343
悲哀的现实
悲哀的现实 2020-11-29 14:32

A project on GitHub that I have a fork of has a new pull requests that I want to pull into my fork that the author has not pulled in yet.

Is there a simple way to ap

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 14:56

    I use a handy dandy script for this. I run the script by typing:

    git prfetch upstream
    

    and it gets all of the pull requests from the upstream fork.

    To create the script make a file ~/bin/git-prfetch.

    The file should contain the following:

    #!/bin/bash
    
    if [ -z "$1" ]; then
        echo "Please supply the name of a remote to get pull requests from."
        exit 1
    fi
    
    git fetch $1 +refs/heads/\*:refs/remotes/$1/\* +refs/pull/\*/head:refs/remotes/$1/pr/\*
    

    Ensure that your path includes the script by setting:

    export PATH="$HOME/bin:$PATH"
    

    You can add this file to ~/.bashrc to make the change permanent.

    Now, make sure you add the fork you want to get the pull requests from:

    git remote add upstream https://github.com/user/repo.git
    

    And then

    git prfetch upstream
    

提交回复
热议问题