Syncing a forked repo in the terminal
A fork is your very own copy of some code which you can make changes locally without fear of breaking anything upstream (more on this later). You are free to add some feature and suggest that new feature be added back to the upstream repository.
GitHub allows you to contribute to open source projects by making your own copy of a repository (repo). This is called a fork
.
A fork is your very own copy of some code which you can make changes locally without fear of breaking anything upstream (more on this later). You are free to add some feature and suggest that new feature be added back to the upstream repository.
Forking creates a new context and a relationship between you and the original repository. The original repo is considered upstream
branch and your fork to you is considered origin
.
Checking to see who is who is very easy. After forking and cloning a repo run the following command in the terminal.
I have forked DefinitelyTyped.
clone repo:
Checking to see who is who is very easy. After forking and cloning a repo run the following command in the terminal.
issue this command in the terminal:
output:
origin
is referring to me, as in my forked copy under my account, you can see this as it has my name mannuelf/DefinitelyTyped.git
in the URL.
GREAT 🚀
Merge upstream/master
What happens if DefinitelyTyped is updated and my fork has gotten out of date. I should git pull in those changes but it's not so straight forward.
You will have to fetch upstream/master and merge upstream/master into your local copy. Wait what the heck is upstream/master? Remember you are origin
and they are upstream
.
Connect to upstream repo
The connection to upstream
is not configured by default, you have to tell your repo where the upstream repo is.
issue this command:
then check your config:
Great, there you can see two new entries into your config upstream
appears twice, once for fetching and once for push.
run:
This will connect upstream
to DefinitelyTyped and fetch all new changes and merge them into my origin branch.
output:
Notes:
Newer projects on GitHub initialise by default to main
branch and not master
. So the command you issue should changed based on the project.
If the project is using main branch issue: