paint-brush
What the FORK Are You Doing to That Repository?!by@balastrong
123 reads

What the FORK Are You Doing to That Repository?!

by Leonardo MontiniMarch 20th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

How to Fork a repository on GitHub is as easy as pressing a button, but why is it required? Wouldn’t just cloning the repository be enough? Here’s a brief video about the most essential GitHub feature to enable collaboration between developers in the open-source world.
featured image - What the FORK Are You Doing to That Repository?!
Leonardo Montini HackerNoon profile picture

How to Fork a repository on GitHub is as easy as pressing a button, we take this for granted, but why is it required? Wouldn’t just cloning the repository be enough?


Here’s a brief video about the most essential GitHub feature to enable collaboration between developers in the open-source world.



Not a fan of videos? You might want to reconsider; it's just a few minutes, and there are a couple of fun gags... anyway, if you insist, here's the written version I drafted right before recording. The content should be pretty much the same :)


Fork a Repository

Today, we're going to talk about one of the most important features of GitHub, and that's forking.

First of all, what does it mean? It is essentially making a copy of a repository from someone else's account to your account.


It’s not like... stealing the repo: you will end up with a copy linked to the original one as you can also see right below the repository name on GitHub.


How a forked repo is displayed on GitHub


So, why do we fork? Well, forking is really important because it allows collaboration. Suppose you find someone else's code that you want to contribute to or add some features to it. You cannot just push your changes in the original repo because you probably don’t have write access.


In that case, you can fork the repository, make the changes in your own copy, and then create a pull request to ask if your changes can be merged back into the original repository.

Why Not Just Clone?

But hold on, what's the difference between forking and cloning? Isn’t git clone faster? Well, cloning is to copy a remote repository in your machine. However, if you clone someone else’s repository, if you don’t have write access, you still cannot push any changes.


Forking, on the other hand, allows you to make changes to the code without affecting the original repo.


To fork a repository, navigate to it on GitHub and click the "fork" button on the top right corner. Once you've forked the repository, you'll have your own copy of the code, and you can run git clone on this one.


If you don’t remember if you already forked a repo, clicking the arrow button here will let you know the answer.

Maintaining a Fork

One thing to keep in mind when forking is that your copy will not automatically sync with the original repository. If the original one gets any changes, you will have to pull those changes into your fork manually.


Don’t worry though, all you have to do is, from your repo, just click the sync button, and then in your local version, make sure to git pull.


The Sync button to keep your repo up to date


Quick tip: When you push changes on a forked repository, don’t forget to always do that in a separate branch, and try to avoid pushing commits on the main.


It’s not mandatory, but it will help you prevent some annoying situations with merge conflicts or unwanted code showing up in your pull requests to the original repo.


Just create a branch every time, and you’ll be fine.

Why Is It Called a Fork?

Also, are you curious as to why it is called a fork? It comes from a command with the same name in Unix.


The Unix command "fork" was named after the idea of a fork in the road, as it creates a new process that splits off from the original process. This term has since been adopted in the software industry, including GitHub, where it refers to creating a duplicate copy of a repository.


Thanks for reading this article; I hope you found it interesting!


Don’t forget to check out my YouTube channel where I talk about GitHub and Open Source

See you soon!