Published: 19.04.2021 | Edited: 09.05.2021 | Tags: 100daystooffload,git
Keep Git fork in sync
Steps below explain to keep the forked version up to date with the upstream branch of a forked repository. I know this was already documented many times, but I was struggling with it for some time, until I have found the workflow that suits me the best, so I documented it.
Create a fork in the UI, clone the forked repository and change directory:
git clone --recurse-submodules email@example.com:peterbabic/a-forked-repository.git cd forked-repository
Add the upstream remote, do this only if remote is not already present:
git remote add upstream firstname.lastname@example.org:ORIGINAL-ACCOUNT/repository.git
Get back to the main branch, if not already there:
git checkout main
Fetch latest changes and add them to the repository:
git pull --rebase upstream main
Push the changes back into the origin (the fork),
--force may be needed:
Repeat last three commands to keep the forked repository updated.
Tip: It is possible to skip writing
--rebase with this setting:
git config --global pull.rebase true
For the completeness, here's how remotes should look like:
git remote --verbose
origin email@example.com:peterbabic/a-forked-repository.git (fetch) origin firstname.lastname@example.org:peterbabic/a-forked-repository.git (push) upstream email@example.com:ORIGINAL-ACCOUNT/repository.git (fetch) upstream firstname.lastname@example.org:ORIGINAL-ACCOUNT/repository.git (push)
This is a 40th post of #100daystooffload.