DEV Community

0 seconds of 0 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
00:00
 
Michelle Duke
Michelle Duke

Posted on • Edited on

5

Using the GitHub CLI to update your repo

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.

twilio-quest-oss-banner.width-800

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

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay