GitHub Fork: All you need to know about.

Sarang Surve
5 min readJul 25, 2023

--

Hey there! So, you know what’s super cool about GitHub? It’s this awesome thing called “forking.” Imagine you stumble upon this really cool project on GitHub, and you want to play around with it, add some new stuff, or suggest improvements. Well, instead of messing with the original project, you can make your own copy of it! It’s like creating a personal playground where you can experiment freely without affecting the original project. And guess what? Your copy is totally separate from the original, so you can modify it however you want without any worries. How awesome is that?! Forking is a big deal in the world of collaborative coding, especially for open-source projects and team collaborations. It’s all about having fun, trying out new ideas, and contributing to the community without messing with anyone’s hard work.

Advantages of using Git Fork

The main advantages of using a Git fork instead of a Git clone, especially for a big group of developers working collaboratively, are as follows:

  1. Isolation: When all the developers clone a repository directly, they end up working in the same branch of the original repo. And that can cause some pesky conflicts and make managing changes a real headache! But, forking lets each developer have their very own copy of the project where they can freely make changes without messing with others’ work. So, it’s like having your own playground to play and experiment with the code!
  2. Collaboration: Forking is like having your own magical copy of a project. So, imagine you and your friends are working on a cool project. You each get your own copy to tinker with without messing up the original. Once you’re happy with your changes, you can easily ask the main team to take a look at what you’ve done. It’s like showing off your awesome work and getting some high-fives before it becomes a part of the big project!
  3. Maintaining the original project: Forks are like magic mirrors! When you make changes in your forked copy, the original repository stays totally untouched until someone (usually the project maintainers) reviews your changes and merges them in using pull requests. It’s like a safety net that keeps the main project stable and allows for controlled updates. So, you can freely tinker and experiment with your fork without worrying about breaking things!
  4. Access control: Forking is kinda cool because it lets the original repository owner stay in the driver’s seat when it comes to deciding who gets to contribute to the main project. They can be the gatekeeper and carefully review and accept pull requests from trusted folks, making sure only top-notch changes make their way in. It’s like having a VIP guest list for the code party! So, rest assured, with forking, quality control is in good hands!

How to use a fork

Create a Fork: Head over to the repository you want to fork and look for that awesome “Fork” button right up in the top-right corner. Give it a gentle click, and bam! You just created a sweet copy of the repo under your very own GitHub account. It feels like claiming your territory in the coding world!

Clone Your Fork: Once you’ve got your forked repo, it’s time to bring it to your local machine! Look for that cool green “Code” button in your forked repo, and click it! Then, grab the URL that pops up.

Now, open your terminal and use the git clone command.

git clone https://github.com/your-username/forked-repo.git

Paste the URL you copied, and hit Enter. You’ve cloned your fork to your computer!

Make Changes: Now that you’ve got the code right on your local machine, Feel free to go wild — create new branches, tinker with files, add new stuff, you name it! It’s like your coding playground where you can let your imagination run wild! You can create new branches, edit files, add new files, etc.

Commit and Push: Now you’ve done some changes to the code, so it’s time to put it back into the remote git repository! Here’s how you do it: first, let’s stage those changes with a simple ‘git add .’ command — that’s like getting your changes ready! Then, Commit with ‘git commit -m “Enter Your commit message here”’ — just add a quick note about your updates! And now, Push your changes to your forked repo on GitHub with ‘git push origin main’ (or the branch you want to use)!

git add .               # To stage the changes
git commit -m "Enter Your commit message here"
git push origin main # Replace 'main' with the branch you want to push to.

Create a Pull Request: So, you’ve made your changes in your fork, and now it’s time to share the changes with the original repository! Head back to the repo you forked from, and look for a “Pull Request” banner to create a pull request. Click on that, and a form will pop up, where you can spill the beans about your awesome changes! Describe what you did, hit that submit button, and ta-da! Your pull request is now submitted and on its way to the original repo’s maintainers for their expert review! Kick back, relax, and wait for the green light to join your changes with the main project!

Updating Your Fork: If you wanna keep your forked repo up-to-date with the latest awesomeness from the original repo, no worries! Here’s the secret sauce! First, add the original repo as an “upstream” remote with this command:

git remote add upstream https://github.com/original-repo-owner/original-repo.git

Then, fetch all the juicy changes from the upstream repo using:

git fetch upstream

Now, it’s time to merge those updates into your local repo! Just switch to the branch you wanna update (usually ‘master’) and run:

git checkout master
git merge upstream/master # Replace 'master' with your branch name if it's different.

Last but not least, push those fresh changes to your forked repo on GitHub with:

git push origin master

And Boom! Your fork is now updated with the latest changes from the original repo! Keep syncing and stay in the loop with all the latest updates!

You got the basic steps on using forks in GitHub! 🌟

Forking is like having your own superpower for collaborating on open-source projects! It’s all about teaming up, making changes, and contributing like a boss to your favorite projects. So, go ahead, fork away, and let the coding adventures begin! 🚀💻

Happy collaborating, and keep spreading the open-source love! 🤝💕

--

--

No responses yet