git

🏠 Homepage 🏠 Syllabus of Day 2 ⬅️ Previous: πŸ”„ Cloning a Repository

5. Forking a Repository

What is Forking?

Forking is the process of creating a personal copy of someone else’s repository on your own GitHub account. This allows you to freely experiment with changes without affecting the original project.

When to Use Forking

You should fork when you do NOT have collaborator access to the repository.

Why Fork Instead of Clone?

How to Fork a Repo on GitHub

  1. Go to the Repository:
    Visit https://github.com/samyak-shrestha/git-repo-example.

  2. Click the β€œFork” Button:
    At the top right of the page, click the Fork button.

  3. Choose Your Account:
    Select your GitHub account as the destination for the fork.

  4. Your Fork is Created:
    You now have a copy at https://github.com/<your-username>/git-repo-example.

Example Workflow: Fork, Clone, and Contribute

  1. Fork the Repository
    As described above.

  2. Clone Your Fork Locally
    git clone git@github.com:<your-username>/git-repo-example.git
    cd git-repo-example
    
  3. Add the Original Repo as Upstream (Optional, for syncing)
     git remote add upstream git@github.com:samyak-shrestha/git-repo-example.git
    
  4. Create a Branch for Your Changes
     git checkout -b my-feature-branch
    
  5. Make Changes, Commit, and Push
     git add .
     git commit -m "Add my feature"
     git push origin my-feature-branch
    
  6. Open a Pull Request
    • Go to your fork on GitHub.
    • Click β€œCompare & pull request”.
    • Fill in the details and submit.

Summary Table

| Topic | Description/Goal | |β€”β€”β€”β€”β€”β€”β€”-|————————————————————–| | Fork | Click β€œFork” on GitHub | | Clone fork | git clone git@github.com:<your-username>/git-repo-example.git | | Add upstream | git remote add upstream git@github.com:samyak-shrestha/git-repo-example.git | | Create branch | git checkout -b my-feature-branch | | Pushing Changes | git push origin my-feature-branch | | Pull Requests | Open PR from your fork to the original repo |


Tip: Forking is the standard workflow for contributing to open source projects when you don’t have write access.

➑️Up Next: πŸ” Opening a Pull Request (PR)