Let say you want to contribute to an interesting project on GitHub
neovim/neovim, first we need to fork it to our GitHub accout
ninovsnino/neovim. All this we need to do that in our own GitHub account.
I’m a vim guy and I really exited on the initiative to make a modern and extendable version of vim, it’s a good example on new and hot open source project on GitHub.
Register and list git alias
Now let’s open our Git Bash console to clone it in our local machine
git clone firstname.lastname@example.org:ninovsnino/neovim
git remote add upstream email@example.com:neovim/neovim
the last command will set the original project with an alias upstream.
We can verify where are origin and upstream pointing it to
$ git remote -v
# origin https://github.com/ninovsnino/neovim (fetch)
# origin https://github.com/ninovsnino/neovim (push)
# upstream https://github.com/neovim/neovim (fetch)
# upstream https://github.com/neovim/neovim (push)
Update local master
If your original public repo is a very popular project there’ll be a lot of updates until a point we couldn’t keep up with, one day you skip monitoring it will be one or more changes will get in.
Now it’s time to sync it,
$ git fetch upstream
remote: Counting objects: 462, done.
remote: Compressing objects: 100% (272/272), done.
remote: Total 462 (delta 259), reused 286 (delta 170)R
Receiving objects: 100% (462/462), 1.53 MiB | 72.00 KiB/s, done.
Resolving deltas: 100% (259/259), done.
bbf6442..a86b1a1 master -> upstream/master
Now we get our master updated in local machine
$ git rebase upstream/master
First, rewinding head to replay your work on top of it...
Fast-forwarded master to upstream/master.
It will make our git history cleaner
Update our GitHub repository
What we have so far is our local machine, master is keep up with upstream, but we still didn’t touch origin, so we’ll update it as well.
$ git push origin master
Username for 'https://github.com': ninovsnino
Password for 'https://firstname.lastname@example.org':
Counting objects: 629, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (183/183), done.
Writing objects: 100% (462/462), 191.74 KiB | 0 bytes/s, done.
Total 462 (delta 334), reused 387 (delta 259)
bbf6442..a86b1a1 master -> master