---
title: Keeping A GitHub Fork Updated
teaser: A git guide on how to keep your GitHub forks updated with its upstream.
tags: git,unix
author: Dan Croak
published_on: 2011-05-02
---

I forked a GitHub repo `thoughtbot/dotfiles` to `croaky/dotfiles` and want to
keep it updated.

## Track

After I forked the repo to your Github account, I did this one time:

    git clone git@github.com:croaky/dotfiles.git
    cd dotfiles
    git remote add upstream git@github.com:thoughtbot/dotfiles.git

## Update

Each time I want to update, from my local `main` branch:

    git fetch upstream
    git rebase upstream/main

The goal of the rebase is to have a cleaner history if I have local changes or
commits on the repo. It's the difference between the the left and the right in
the image below.

[![image](http://images.thoughtbot.com/ui/pull-rebase-vs-pull.jpg)](http://gitready.com/advanced/2009/02/11/pull-with-rebase.html)

If you want to learn more rebasing a forked repo on top of main, [Git interactive rebase, squash, amend and other ways of rewriting history](https://thoughtbot.com/blog/git-interactive-rebase-squash-amend-rewriting-history#rebase-on-top-of-main) provides more detail about it.

## Commit rights upstream

If I also have commit rights to the upstream repo, I can create a local
`upstream` branch and do work that will go upstream there.

    git checkout -b upstream upstream/main
