But I get an error "! [rejected]" and something about "non fast forward"
That's because Git can't merge the changes from the branches into your current master. Let's say you've checked out branch master
, and you want to merge in the remote branch other-branch
. When you do this:
$ git pull origin other-branch
Git is basically doing this:
$ git fetch origin other-branch && git merge other-branch
That is, a pull
is just a fetch
followed by a merge
. However, when pull
-ing, Git will only merge other-branch
if it can perform a fast-forward merge. A fast-forward merge is a merge in which the head of the branch you are trying to merge into is a direct descendent of the head of the branch you want to merge. For example, if you have this history tree, then merging other-branch
would result in a fast-forward merge:
O-O-O-O-O-O
^ ^
master other-branch
However, this would not be a fast-forward merge:
v master
O-O-O
\
\-O-O-O-O
^ other-branch
To solve your problem, first fetch the remote branch:
$ git fetch origin other-branch
Then merge it into your current branch (I'll assume that's master
), and fix any merge conflicts:
$ git merge origin/other-branch
# Fix merge conflicts, if they occur
# Add merge conflict fixes
$ git commit # And commit the merge!
You have to add the original repository (the one you forked) as a remote.
From the GitHub documentation on forking a repository:
Once the clone is complete your repo will have a remote named “origin
” that points to your fork on GitHub.
Don’t let the name confuse you, this does not point to the original repo you forked from. To help you keep track of that repo we will add another remote named “upstream”:
$ cd PROJECT_NAME
$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
$ git fetch upstream
# then: (like "git pull" which is fetch + merge)
$ git merge upstream/master master
# or, better, replay your local work on top of the fetched branch
# like a "git pull --rebase"
$ git rebase upstream/master
There's also a command-line tool (hub
) which can facilitate the operations above.
Here's a visual of how it works:
See also "Are Git forks actually Git clones?".
Best Answer
I had similar issue. Here’s what worked for me
Pre-req
On Github
YourJenkinsURL/github-webhook/
On Jenkins
+refs/pull/*:refs/remotes/origin/pr/*
${sha1}
That’s it. You are all set. Creating a PR on master branch of your repo should now trigger your Jenkins Pipeline job
Some observations