GitHub is a major platform for open source contributions and also an amazing way to gain knowledge contributing to others projects. One learns about the latest modules used, different coding styles and also get in touch with various developers around the world and build the community.
While using GitHub and contributing to various apps, it is important we keep our fork repository updated with the master repository as there might be various changes done by various contributors and if we have that updated, it will help us in our future issues and contributions and also use the updated version of the project. Here is the official definition of syncing fork with master
“Getting the latest changes in the master repository after you have forked it without losing the current changes you have made in your local repository.”
So, how do we do it?! If you are a new developer and also new to open source, then this is an important command structure you got to learn which will make your path to open source contribution smooth.
Following are the steps to Sync your fork with the master:
Step 1: Open your command line or terminal in git bash.
Step 2: Run the following command in your terminal to see the current configured remote repository in your fork:
git remote -v
Step 3: Run the following command:
git remote add upstream https://github.com/(original_owner_or_organisation/(original_repository).git
This particular command will help you add the upstream which means the link to master repository from which you have forked.
Step 4: Check your remote now by running the following command again:
git remote -v
It will show something like this, which indicates your own local repository and also your master repository.
Step 5: Fetch the changes from the upstream with following command:
git fetch upstream
Now, that you’ve set the upstream, it’s time to fetch the changes from the upstream(master repository) that have been made since the time you forked. But make sure, you are in your master branch or any main branch before you run this command.
Step 6: Merge the fetched changes:
git merge upstream/master
We’ve reached the milestone finally and now it’s all left to merge the changes that you’ve have fetched from your master to the local repository. This command will help you do that.
After you have run all these commands in stepwise order correctly, you will have all the changes made in the master updated in your local repository successfully.
- Using GitHub with SSH (Secure Shell)
- How to Upload a Project on Github?
- Issues in GitHub
- Making a Github Bot
- How to Upload Project on GitHub from Android Studio?
- How to Trigger WebHooks without Events - Probot Github App
- GitHub App to Build Form using Typeform and Probot
- How to Upload Project on GitHub from Pycharm?
- GitHub App to Add or Remove Labels to Issues
- Difference Between Git and GitHub
- Link your GitHub Account with R Studio
- How to Publish a Static Website on GitHub?
- How to add a README to your GitHub profile?
- Common Git Problems and Their Fixes
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.