Sync Forked Repository With Upstream 🔁✔️
Here's the situation, You have forked a repository on GitHub, you have
made your changes and sent a pull request and that request has been merged.
This will set your fork's master to be the same as upstream's master.
Now you are free to make any changes you wish to make.
If you just want to get the changes from upstream you can do
Thank you for reading, hope you found this useful, see you in the next one.
Now you want to make further changes, but the repository mentions that you are
X commits ahead or/and X commits behind upstream repository.
So how do you sync it?
You can delete your fork and fork the original repository again, but that is a
very tedious thing to do.
Here's another way to do this:
1. Clone your fork
git clone https://github.com/yourname/repo.git
cd yourname/repo
2. Add upstream remote
git remote add upstream https://github.com/original-author/repo.git
git fetch upstream
3. Ignore all changes in fork and sync with upstream
git reset --hard upstream/masterOnly do this if you have no changes on your fork that you will like to keep.
git push -f origin master
This will set your fork's master to be the same as upstream's master.
Now you are free to make any changes you wish to make.
If you just want to get the changes from upstream you can do
git pull upstream masterJust a word of caution: Always be extra careful when using the -f or --force option.
git push origin master
Thank you for reading, hope you found this useful, see you in the next one.
Comments
Post a Comment