Github Fork in Git
🚀 GitHub Fork – A Guide to Forking Repositories
A fork in GitHub is a personal copy of someone else's repository. It allows you to modify the project without affecting the original. Forking is commonly used for contributing to open-source projects or making independent changes.
📌 Why Fork a Repository?
✅ Work on someone else's project without permission.
✅ Experiment with changes before proposing them.
✅ Contribute to open-source projects via Pull Requests (PRs).
🔥 How to Fork a Repository on GitHub
1️⃣ Forking the Repository
- Go to the repository you want to fork on GitHub.
- Click the Fork button (top-right corner).
- GitHub will create a copy under your account.
2️⃣ Clone the Forked Repository
Once forked, clone it to your local machine:
git clone https://github.com/your-username/repository.gitcd repository
3️⃣ Add the Original Repository as an Upstream Remote
To keep your fork updated with the latest changes from the original project:
git remote add upstream https://github.com/original-owner/repository.git
Verify remotes:
git remote -v
4️⃣ Make Changes and Commit Locally
- Create a new branch:
git checkout -b new-feature - Make edits, then stage and commit:
git add .git commit -m "Added a new feature" - Push changes to your fork:
git push origin new-feature
5️⃣ Create a Pull Request (PR) to the Original Repository
- Go to your forked repo on GitHub.
- Click "Compare & pull request".
- Add a title and description explaining your changes.
- Click "Create pull request".
- The original project owner will review and merge it if approved.
6️⃣ Keeping Your Fork Updated
If the original repo updates, sync your fork:
git checkout maingit fetch upstreamgit merge upstream/maingit push origin main
🎯 Summary of Forking Workflow
1️⃣ Fork the repository on GitHub
2️⃣ Clone the fork to your local machine
3️⃣ Add the original repo as an upstream
4️⃣ Create a new branch and make changes
5️⃣ Push changes to your fork
6️⃣ Open a Pull Request to contribute
7️⃣ Keep your fork updated