Lately my friend ask me: „I’ve forked repository from github.com, how can I update it?”. I’ll write an answer for this question here.
Preparation
As example I’ll use Kotlin Language repository from github.com (I like Kotlin and I’m proud of it :))
First we clone repository:
1 2 3 |
git clone git@github.com:marioosh/kotlin.git cd kotlin |
marioosh
is my github’s username use your own in this place. Don’t forget to fork the repository you are interested in.
Upstream tracking
Now it’s time to set up upstream
branch. This branch point to original repository you’ve forked from.
1 2 |
git remote add upstream git@github.com:JetBrains/kotlin.git |
In the repository should be now 2 branches:
1 2 3 4 5 6 |
> git remote -v origin git@github.com:marioosh/kotlin.git (fetch) origin git@github.com:marioosh/kotlin.git (push) upstream git@github.com:JetBrains/kotlin.git (fetch) upstream git@github.com:JetBrains/kotlin.git (push) |
Fetching
Sync process needs two steps – fetching and merging. Fetch from remote repository will bring in commits, that are stored in your local repository.
1 2 |
git fetch upstream |
To finish syncing process we have to merge upstream
into our master branch.
1 2 3 |
git checkout master git merge upstream/master |