Tonight was a rainy, cold night in my town, so I spent the evening trying to get my four pull requests in for Digital Ocean’s Hackoberfest. I found myself updating an old fork on my Github page and reflecting on the questions I had when starting with Git and Github. How to update my personal fork on Github from the original repository was one of my first tasks I learned, and I thought I’d take the opportunity to pass the knowledge along in the spirit of Hackoberfest.

I have a fork of Kubernetes in my Github account for preparing pull requests. I can clone my repository to my development workstation using git clone:

> git clone [email protected]:kelcecil/kubernetes.git
Cloning into 'kubernetes'...
remote: Counting objects: 162966, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 162966 (delta 0), reused 0 (delta 0), pack-reused 162960
Receiving objects: 100% (162966/162966), 124.80 MiB | 8.79 MiB/s, done.
Resolving deltas: 100% (106653/106653), done.
Checking connectivity... done.

The URI used in the git clone command is stored as a remote named origin. We can verify this very easily using git remote:

> git remote -v                                                                   
origin  [email protected]:kelcecil/kubernetes.git (fetch)
origin  [email protected]:kelcecil/kubernetes.git (push)

This remote named origin is the repository location we are referring to when we perform git push origin master or git pull origin master. origin is only one possible location, and we can add other remote repositories such as the upstream repository that we’d like to pull data from. Let’s add the main Kubernetes repository as a remote named upstream using git remote add.

> git remote add upstream [email protected]:kubernetes/kubernetes.git
> git remote -v
origin  [email protected]:kelcecil/kubernetes.git (fetch)
origin  [email protected]:kelcecil/kubernetes.git (push)
upstream        [email protected]:kubernetes/kubernetes.git (fetch)
upstream        [email protected]:kubernetes/kubernetes.git (push)

We can now easily update our code from the upstream Kubernetes repository with a simple git pull. You can then push your repository to origin to update your forked repository.

> git pull upstream master
...
> git push origin master
...

Excellent work! Our forked repository is now up to date with the upstream repository, and we’re ready to hack on our favorite project!