Open In App

Sync your fork with master in GitHub

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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.


Last Updated : 12 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads