Skip to content

MergeFromUpstream

Jonathan Yates edited this page Sep 12, 2019 · 1 revision

How to merge the most recent work on the official repository into my fork

To be done only once

  • Clone your fork
  • Run the following command to reference the official repository as "upstream":

git remote add upstream https://github.com/optados-developers/optados.git

Every time you want to merge

  • first commit all your changes (and if you want, also push them to your repository)
  • then, run git pull upstream develop to merge all "official" changes in your branch

Merge behaviour (and merge conflicts)

At this stage, three different things can happen:

  • Changes have happened only on different files. Then they are ported into your branch, you can continue to work happily.
  • Changes have also happened to files you edited, but git could merge without problems. It will ask you then to store a message for a commit that represents the merge, you can simply accept the default message.
  • There are some conflicts you have to resolve. Then, do a git status, files already 'added' are successfully merged, while files marked as 'both modified' need to be fixed - open them, fix all conflicts (your version and the official version are marked with <<<<<< and >>>>>> signs). When you fix everything, add these files and then commit + push to finish the merge operation.

Note! If, while merging, you notice there are other things to fix, it's good practice to first complete the merge, commit, and then continue to fix (you can push at the end). Otherwise, your fixes will be "hidden" inside the commit representing the merge.

Merging from a pull request

If you want to be able to pull/merge from pull requests sent on the upstream repository, add the following line the [remote "upstream"] section of your .git/config file in the top folder of your repo:

fetch = +refs/pull/*/head:refs/remotes/upstream/pr/*

Once you do this, you can merge from a pull request using:

  • git fetch upstream followed by
  • git merge upstream/pr/8 (replace 8 with the pull request ID you want to merge from)