Forking a repository allows you to create your own copy of the project under your GitHub account. This is helpful when you want to make changes to the code without affecting the original project.
-
Visit the Organization's Repository
- Navigate to the repository of the organization that you want to fork. For example,
https://github.com/ORG_NAME/REPO_NAME.
- Navigate to the repository of the organization that you want to fork. For example,
-
Fork the Repository
- In the upper-right corner of the repository page, you’ll see a
Forkbutton. Click it. - GitHub will create a copy of the repository under your account. The new repository will have the same name as the original, but it will now be located at
https://github.com/YOUR_USERNAME/REPO_NAME.
- In the upper-right corner of the repository page, you’ll see a
Once the repository has been forked, you can clone it to your local machine to work on it.
-
Navigate to Your Forked Repository
- After forking, go to the repository under your GitHub profile:
https://github.com/YOUR_USERNAME/REPO_NAME.
- After forking, go to the repository under your GitHub profile:
-
Get the Repository URL
- On your forked repository page, click the green
Codebutton, and copy the repository URL.- You can choose between HTTPS or SSH.
- Example HTTPS URL:
https://github.com/YOUR_USERNAME/REPO_NAME.git - Example SSH URL:
git@github.com:YOUR_USERNAME/REPO_NAME.git
- On your forked repository page, click the green
-
Open a Terminal or Command Line
- Navigate to the directory where you want to clone the repository.
-
Clone the Repository
- Use the
git clonecommand followed by the copied URL to clone the repository:git clone https://github.com/YOUR_USERNAME/REPO_NAME.git
- If you are using SSH:
git clone git@github.com:YOUR_USERNAME/REPO_NAME.git
- Use the
-
Navigate into the Cloned Repository
- Change to the directory of the cloned repository:
cd REPO_NAME
- Change to the directory of the cloned repository:
To keep your fork updated with the latest changes from the original repository, you'll want to add a remote pointing to the original repo (known as upstream).
-
Add Upstream Remote
- Inside your cloned repository, add the original repository as an
upstreamremote:git remote add upstream https://github.com/ORG_NAME/REPO_NAME.git
- If you are using SSH:
git remote add upstream git@github.com:ORG_NAME/REPO_NAME.git
- Inside your cloned repository, add the original repository as an
-
Fetch the Latest Changes from Upstream
- To update your fork with any new changes made to the original repo:
git fetch upstream
- To update your fork with any new changes made to the original repo:
-
Merge the Changes into Your Fork
- Merge the latest changes from the upstream repository into your local fork:
git merge upstream/main
- Replace
mainwith the appropriate branch name if the repository uses a different default branch.
- Merge the latest changes from the upstream repository into your local fork:
Now that you've cloned the repository, you can start working on the project. You can create branches, make changes, and push them to your forked repository.
To push changes:
git add .
git commit -m "Your commit message"
git push origin main