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

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

git remote add upstream

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. Merge your custom changes to the rebased code:

git pull

7. Push your updated fork back to your Github (Gitlab):

git push

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.

One thought on “Working with git – Keeping a fork synchronized with the original repo

Leave a Reply

Your email address will not be published. Required fields are marked *