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 email@example.com:githubusername/forked-project.git
3. Add the original repository to be able to synchronize our fork with it:
git remote add upstream firstname.lastname@example.org: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. Merge your custom changes to the rebased code:
7. Push your updated fork back to your Github (Gitlab):
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.