common workflow in oss contributions is fork → edit → pr
when making repeated contributions, the master branch of the fork needs to be in sync with the original – the upstream
and here's one way to do that
we want local master to :
- fetch and pull from
upstream/master - push to
fork/master
we can skip having to specify the remote each time by setting up a remote as follows:
- <remote shortname>
- fetch url: <upstream url>
- push url: <fork url>
these steps will setup a remote from scratch
- set up a remote
git remote add <name> <upstream-url>
git remote set-url <name> --push <fork-url>
- [optional] checking your settings
git remote show <name>
# this should return something like:
# ----
# remote <name>
# Fetch URL: <upstream url>
# Push URL: <fork url>
# etc...
- set your master branch to track
<name>/master
# if you aren't already at master
git checkout master
# set master to track your new remote
git branch --set-upstream-to=<name>/master
et voilà~ !
as far as git is concerned, your master branch should be in sync with the remote master branch at <name>. so when you run git pull at master, it pulls from upstream when you run git push it pushes to fork but treats both as the same remote.
this applies for a configuration where it is just a linear relationship between one local, one fork and one upstream. when there are multiple locals with the fork being centralised, pulls will need to be made from the fork as well. likewise for multiple remotes in the event of collaboration outside of the upstream.