Overview

How to Work With Forks on Remote Repositories With Git

Step 1: Once you forked a remote repository, add the original repository as a new remote called “upstream”

git remote add upstream <ORIGINAL_REPOSITORY_URL>

Step 2: Fetch the branches of the upstream remote

git fetch upstream

Step 3: Update your branch with the upstream

git rebase upstream/<BRANCH>

Step 4: Force push the updated branch to your fork’s remote repository

git push origin <BRANCH> --force

Step 5: Start working on the updated fork using a new feature branch

git switch -c <FEATURE_BRANCH>

Step 6: Work as usual, write great code and add your commits

Step 7: Before pushing your changes to create a merge request, fetch and rebase again to upstream

git fetch upstream

git rebase upstream/<BRANCH>

Step 8: Push the feature branch

git push -u origin HEAD

Step 9: Create the merge request using the url given in the push status message (example for gitlab, actual behaviour may differ depending on used git server software)

https://<HOST>/<USER>/<REPO>/-/merge_requests/new?merge_request%5Bsource_branch%5D=<FEATURE_BRANCH>


Written by
Christian Konrad
Product Manager, UI/UX Designer and Web Developer in Frankfurt a. Main, Germany. T-shaped, focused on building experiences by forming habits.