Forking a repository on GitHub creates a personal copy of someone else’s repository under your own GitHub account. This allows you to experiment with changes or contribute to the original project without affecting it directly. Here’s a concise guide to forking a repository on GitHub:
Steps to Fork a Repository on GitHub:
- Navigate to the Repository: Go to the GitHub page of the repository you want to fork (e.g., https://github.com/username/repository-name).
- Fork the Repository:
- In the top-right corner of the repository page, click the Fork button.
- If you belong to multiple organizations, select the account or organization where you want the forked repository to reside.
- Optionally, you can customize the repository name or description and choose to copy only the default branch (recommended for most cases).
- Click Create fork. This creates a copy of the repository under your account (e.g., https://github.com/your-username/repository-name).
- Clone Your Fork (to work locally):
- Navigate to your forked repository on GitHub.
- Click the Code button and copy the HTTPS or SSH URL.
- In your terminal, run:
- bash
- Copy
gitclonehttps://github.com/your-username/repository-name.git- Navigate to the cloned directory:
- bash
- Copy
cdrepository-name
- Add the Upstream Repository (to stay in sync with the original):
- Add a remote for the original repository (referred to as “upstream”):
- bash
- Copy
git remote add upstream https://github.com/original-owner/repository-name.git
- Make Changes:
- Create a new branch for your changes:
- bash
- Copy
git checkout -b feature-branch- Make your changes, commit them, and push to your fork:
- bash
- Copy
git add .git commit -m"Your commit message"git push origin feature-branch
- Create a Pull Request (PR) (to contribute back):
- Go to your forked repository on GitHub.
- You’ll see a prompt to create a pull request for your recently pushed branch. Click Compare & pull request.
- Select the original repository as the base and your branch as the compare branch.
- Add a title and description for your changes, then click Create pull request.
- Sync Your Fork (to keep it updated):
- Fetch and merge changes from the original repository:
- bash
- Copy
git fetch upstreamgit checkout maingit merge upstream/maingit push origin main
Key Points:
- Fork vs. Clone: Forking creates a copy on your GitHub account, while cloning downloads a repository to your local machine. A fork remains independent unless you sync it with the upstream repository.
- Purpose: Forking is ideal for contributing to open-source projects, testing changes, or using someone else’s code as a starting point for your own project.
- Permissions: You can fork any public repository. For private repositories, you need permission from the owner.
- Mobile Forking: You can fork a repository using GitHub’s mobile interface by clicking the Fork button on the repository page.

- GitHub CLI: Alternatively, use the GitHub CLI to fork:
- bash
- Copy
gh repo fork https://github.com/original-owner/repository-name --clone- This forks and clones the repository locally.