DEV Community

Play Button Pause Button

Using the GitHub CLI to update your repo

Michelle Mannering
Developer Relations | Hackathon Queen | Community Manager
・Updated on ・2 min read

Have you ever forked a repo, only to come back to it months later and realise your fork is totally out of date?

This is what happened to me this week whilst live coding. We were working through the Flame of Open Source on Twilio Quest. It had been a while since I'd completed this mission. We were going over the quest, talking about open source, how to get involved, and how to find good projects.


The Flame of Open source uses an open source repo to show you how to contribute to open source. Since I'd already done this mission, I had the repo forked on my GitHub account, and as a local git repository. But the fork was now 759 commits behind the main branch. One way around this would be to delete the repo and re-clone it.

But there's a better way - updating the repo to match the main branch. You can use the command line with GitHub to do this.

First, navigate to your local git repository:

cd [file path]

Now we need to grab the path to the main branch you originally forked it from:

git remote add upstream [URL ending in *.git]

Then pull this into your local repository:

git remote pull upstream main

During the above step, make sure you're on the right branch. If you're not on the correct branch, use git checkout [branch name] to switch to the correct branch (this is what I did wrong originally) 🀦

Now everything is up to date locally. All you need to do is push all the changes back to GitHub:

git push

Everything now looks good. One of the great things about live streaming is you can learn on the go from people around you. If you want to check out this 🍡 Twilio Quest and Tea 🍡 stream, you can watch the recording on Twitch. Or come and join us sometime at MishManners.

Twitter cardSmall

Discussion (0)