Resources

Forking an Existing Project on GitHub

Say you find an amazing project on GitHub and you want to try it out. You can fork the repository to your own account and then clone it to your local system. This guide will help you do that.

1. How to Fork a Repository

Forking a repository allows you to create a personal copy of someone else’s repository on GitHub, so you can modify and contribute back to the original project.

Steps to Fork a Repository

  1. Go to the repository you want to fork on GitHub.
  2. Click the Fork button in the top right corner.
  3. GitHub will create a copy of the repository under your account.

2. How to Clone a Forked Repository

After forking, you need to clone the repository to your local system to start making changes.

git clone git@github.com:your-username/repository-name.git

Clone the Repository Using HTTPS

git clone https://github.com/your-username/repository-name.git

Navigate into the repository:

cd repository-name

3. Open the Repository in VS Code

Once the repository is cloned, you can open it in VS Code.

code .

This will launch Visual Studio Code with the repository opened.

4. Set Up Your GitHub SSH Keys in Local System

To authenticate your GitHub operations without entering credentials every time, refer to the guide here: Git Project Setup Guide

5. Update Remote URL After Forking

When you fork a repository and clone it, the .git file may still be connected to the original user's repository. You need to update it to point to your fork.

Check the Current Remote URL

git remote -v

You might see something like this:

origin  git@github.com:original-user/repository-name.git (fetch)
origin  git@github.com:original-user/repository-name.git (push)

Update Remote to Point to Your Fork

  1. Remove the existing remote:
    git remote remove origin
    
  2. Add your own fork as the new origin:
    git remote add origin git@github.com:your-username/repository-name.git
    
  3. Verify the change:
    git remote -v
    
    Expected output:
    origin  git@github.com:your-username/repository-name.git (fetch)
    origin  git@github.com:your-username/repository-name.git (push)
    
  4. Push your local changes to your forked repository:
    git push -u origin main
    

If you want to sync your fork with the original repository:

  1. Add the original repository as upstream:

    git remote add upstream git@github.com:original-owner/repository-name.git
    
  2. Verify remotes:

    git remote -v
    
  3. Fetch updates from upstream:

    git fetch upstream
    
  4. Merge upstream changes into your fork:

    git checkout main
    git merge upstream/main
    

Now your fork is up to date with the original repository.


This guide provides a structured approach for forking, cloning, setting up authentication, updating remote repositories, and managing GitHub accounts locally.