Git & GitHub Tutorial

Rahul's Profile

GitHub Fork

1. What is a Fork?

A fork is a personal copy of someone else's repository on your GitHub account. It allows you to freely experiment with changes without affecting the original project.

Forks are used to propose changes via pull requests or to use someone else's project as a starting point.

GitHub Fork Concept

2. How to Fork a Repository

To fork a repository:

  • Go to the original repository on GitHub
  • Click the Fork button in the top right
  • GitHub creates a copy in your account
Fork Repository on GitHub

3. Clone Your Fork

After forking, clone the repository to your local system:

git clone https://github.com/your-username/forked-repo.git

This creates a local copy of your fork.

4. Add Remote to Original Repo (Upstream)

To keep your fork updated with the original repo, first add the original as a new remote:

git remote add upstream https://github.com/original-user/original-repo.git
git remote -v

This shows both origin (your fork) and upstream (original repo).

5. Sync Your Fork

To sync your fork with the latest changes from the original repository:

git fetch upstream
git checkout main
git merge upstream/main

Then push the updated branch to your fork:

git push origin main

6. Contribute via Pull Request

Make your changes in a new branch:

git checkout -b my-feature

Commit and push the branch:

git push origin my-feature

Then go to your GitHub fork and click Compare & pull request to propose changes to the original repository.