How do I update a GitHub forked repository?
How to sync your forked repository to the original want. This is a great way of participating on Open Source without having conflicts in your code.
This can work for another provider different to GitHub but for this exercise I´m going to focus on GitHub.
Remote Repositories
We can look at which repositories we are pointing to.
git remote -vFor example:
origin git@github.com:victoryoalli/framework.git (fetch)
origin git@github.com:victoryoalli/framework.git (push)As you can see I only have the ones pointing to my repository so I´m going to add another one pointing to the original repository in my case is `https://github.com/laravel/framework.git``
We need to have our own origin fetch and push url repositories and the original repository to fetch from there.
I´m going to add the original one to the upstream
git remote add upstream https://github.com/laravel/framework.gitAnd now if we execute git remote -v we will see something similar to the following:
origin git@github.com:victoryoalli/framework.git (fetch)
origin git@github.com:victoryoalli/framework.git (push)
upstream https://github.com/laravel/framework.git (fetch)
upstream https://github.com/laravel/framework.git (push)We update the original repository
git fetch upstreamNow you can move back to your origin master or the branch that you want to have updated. In my case is master and I will use --track to have master as my default.
git checkout --track origin/masterNow that I´m on my own master branch I can merge with the original branch of my desire.
git merge upstream/masterAnd That´s it! :)