Sync your fork with master in GitHub

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.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.