At times there is a need to update your forked repository with the recent commits which happened on the main repository, and to update it we generally use git bash & console but what if I tell you that there is a very simple way of doing this?
And the way is to directly update your fork on Github's website on the forked repository page.
Most of you who are an avid git and github user might already know about this small trick but those who don't know about this or want to learn about it do give it a read 👉
Steps to Update a Fork in Github :
Step-1 : Go to your forked repository on GitHub.
Step-2 : Now you must be seeing a white label like this saying - 'this branch is behind commits' with a 'pull requests' button. Click on that "Pull request" button on the right.
Step-3 : Now you must be seeing a page saying 'There isn't anything to compare' this happens because what GitHub does is, it compares your repository (head fork) with the main repository (base fork) and as you have not made any commits or changes therefore it shows nothing.
But now you can also see 'switching the base' link. So click on “switching the base” link.
Now what it will do is, it will switch both the things that are, change your fork to the base, and the original to the head fork.
Step-4 : After applying the above steps now you will observe that there are a lot of commits and changes. You can also see that the "Create Pull request" button is active . Click on “Create Pull Request” button, give your pull request a name, Click “Send Pull Request”. You have successfully sent a PR to your own forked repository.
Step-5 : Now in your forked repository you will spot a pull request. Click “Merge Pull Request” and Click “Confirm Merge”.
So there you have it the easiest way to update/sync your forked repository directly on GitHub by just sending a pull request. I hope you learnt something from this today.
Top comments (2)
This has been by far the most confusing topic for me, when it comes to Github. Thanks a lot for clarifying.
Now, I'm trying to figure out the difference between "git pull" and "git fetch upstream".
Well I am glad that my article helped you.
And your doubt is legit. Often times many of us get confused between "git pull" and "git fetch". The basic and simple difference between the two is that "git fetch" only checks for changes in your repository and "git pull" checks for the changes and then merges it to the repository.