Working with git

Keeping a fork synchronized with the original repo

MATMOZ d.o.o., Matjaž Mozetič

Working with git

Keeping a fork synchronized with the original repo

This article is not intended to write about what git is, that part is already widely documented online. But there are still some problems with understanding the basic functions needed for keeping a main repository and forked repository synchronized, thus I decided to write down this simplified guide through some basic features.

We want to fork a Github or GitLAB repository, but we still want to keep it updated with it's original repository:

1. Fork a repository through the Github (or GitLAB) UI

2. Clone our forked repository to our local machine
git clone git@github.com:githubusername/forked-project.git

3. Add the original repository to be able to synchronize our fork with it:

git remote add upstream git@github.com:originalgituser/original-project.git

4. Pull the original repository upstream updates:
git fetch upstream

5. Rebase the fetched commits to your fork's branch:
git rebase upstream/branchname

6. Push (force) your updated fork back to your Github (Gitlab):
git push -f

Navigate to your Github (GitLab) page and you'll see, that your fork is not falling behind the source repository anymore.

Next time we'll go through the extremely useful submodule features.