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
- Go to the repository you want to fork on GitHub.
- Click the Fork button in the top right corner.
- 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.
Clone the Repository Using SSH (Recommended)
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
- Remove the existing remote:
git remote remove origin
- Add your own fork as the new origin:
git remote add origin git@github.com:your-username/repository-name.git
- Verify the change:
Expected output:git remote -v
origin git@github.com:your-username/repository-name.git (fetch) origin git@github.com:your-username/repository-name.git (push)
- Push your local changes to your forked repository:
git push -u origin main
6. Link Your Fork to the Original Repository (Upstream)
If you want to sync your fork with the original repository:
-
Add the original repository as upstream:
git remote add upstream git@github.com:original-owner/repository-name.git
-
Verify remotes:
git remote -v
-
Fetch updates from upstream:
git fetch upstream
-
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.