It is not unusual for a number of forks to accumulate in your Github account. If you spend some time working on a fork, you will first want to update it, as the author of the original may have made changes in the meantime. This blog post describes how to do this in the shell.
- Open Terminal (or iTerm, for example) and use
cd
to change to the local repository. - Make sure the correct branch is activated. Typically this will be
master
— ormain
for newer repositories.
$ git checkout main
- Before the update can be performed, it is necessary to check whether the original repository (the original upstream) is known. This can be checked with the following command:
$ git remote -v
origin https://github.com/xern/imessage_reader.git (fetch)
origin https://github.com/xern/imessage_reader.git (push)
- In this case, only the forked repository is displayed. Therefore, it is necessary to add the original repository, which is achieved with the instruction shown below, adjusting the original address within
<>
accordingly.
$ git remote add upstream <https://github.com/original_owner/original_repository.git>
- Now, if you run
git remote -v
, you will get the following output:
origin https://github.com/xern/imessage_reader.git (fetch)
origin https://github.com/xern/imessage_reader.git (push)
upstream https://github.com/niftycode/imessage_reader.git (fetch)
upstream https://github.com/niftycode/imessage_reader.git (push)
- Now it’s time to fetch the changes:
$ git fetch upstream
- The changes can then be applied to the forked repository:
$ git merge upstream/main
- Finally, the changes are uploaded to your own remote fork with
push
:
$ git push
After these steps are completed, the original repository and the fork are back in sync.