DEV Community

Cover image for Forks in GitHub
João Ricardo Mattedi Cetto for LEDS

Posted on • Edited on

Forks in GitHub

In this post, I will introduce a important Git/GitHub feature: Forks

FORK

A fork creates an exact copy of the original repository within the user’s profile, while maintaining a link to the source repository. The primary purpose of a fork is to allow users to modify the original project, experiment with new features, or contribute to the project without directly impacting the main repository.

MAIN USES OF FORK

  • Collaboration in Open-Source Projects: Developers can contribute to projects without needing direct permission from the original repository;

  • Project Personalization: Users can make modifications to suit their specific needs while maintaining a separate repository.

HOW TO MAKE A FORK?

1. Navigate to the repository you wish to fork and click on the "Fork" option:

2. Create your fork by selecting the repository:

3. Copy the clone link of your forked repository to your local machine. You can then make changes or implement new features:

4. Clone the repository in your IDE and begin coding!!

$ git clone https://github.com/JoaoRicardoCetto/RNA-Evolutiva-C-.git
Cloning into 'RNA-Evolutiva-C-'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (3/3), 4.74 KiB | 4.74 MiB/s, done.
Enter fullscreen mode Exit fullscreen mode

5. Enter the local repository, open the folder in your IDE, make your modifications, add them to the stage, commit and push it to make a pull request.

$ git commit -am "adding to the stage and committing"
warning: in the working copy of '.vscode/settings.json', LF will be replaced by CRLF the next time Git touches it
[main eedc221] adding to the stage and committing
 1 file changed, 1 insertion(+), 1 deletion(-)
Enter fullscreen mode Exit fullscreen mode

6. Once you have made your changes and committed them, you can create a pull request to the main repository, suggesting your modifications to be merged into the original project.

OBS: To incorporate commits and updates from the upstream repository into your fork, use the following command: git pull upstream main.

This command fetches the latest changes from the upstream repository’s main branch and merges them into your local fork. Make sure you've previously set up the upstream repository with the correct URL:
git remote add upstream https://github.com/Owner-Name/Repository-You-Forked

This ensures that your fork stays in sync with the original project.

Did you enjoy the post? If you’d like to explore more Git and GitHub features, check out: How to use Git Stash

Top comments (0)