Coolest Guides on the Planet

coolest guides on the planet

Coolest Guides On The Planet

  • Home
  • macOS
  • WebDev
  • All Posts
  • Contact

Sync’ing a GitHub Fork via the Command Line

September 5, 2016 Leave a Comment

This tutorial looks at keeping a GitHub fork syn’ced and updated with the original repo, it involves forking a repo from someone else’s account to your GitHub account, making a local copy of your fork via the command line,  and then fetching any changes of the original repo and then pushing those changes back to your GitHub fork.

Some terms we’ll be using…

  • yourname = Your GitHub account name
  • theirname = Original Repo account name
  • master = branch we are working on
  • the-repo.git = the name of the repo

Forking the Original Repo from Github

github-fork-repo

First up is to make an actual fork of the original rep to your GitHub account, go to the repo you want and click the Fork button, this will add a copy of it to your Github account, take a note of the branches in use, this guide uses the master branch.

repo-tab

Once you have done that you’ll see the forked repo in your Repositories tab.

Cloning Fork Locally

Next up is to clone your fork locally so you can use the code in your local development environment, you grab the address of your forked repo on GitHub via the clone/download green button click the clipboard to copy the address.

github-clone-address

 

Then crank open your Terminal app and navigate where you want the repo via the command line on your local machine and clone a copy of it…

git clone [email protected]:yourname/the-repo.git

So now you have your fork on GitHub and lets say the branch you are working with is master, the GitHub fork is known as origin/master and you also have your local version of the repo which is the branch known as master.

Run git remote to see the GitHub fork

git remote -v
origin [email protected]:yourname/the-repo.git (fetch)
origin [email protected]:yourname/the-repo.git (push)

You will see the fetch and pull remote addresses of the fork on your GitHub account as above – the next thing to do is to include the original repo so you can pull down any changes it has had since you forked it earlier.

Adding the Original Repo as an upstream remote

So you now have the forked GitHub repo as a remote that you can push changes to but what about updating your local forked repo with any changes/updates from the original repo, you need to add that as an upstream remote…

git remote add upstream https://github.com/theirname/the-repo.git

Then run

git remote -v
origin [email protected]:yourname/the-repo.git (fetch)
origin [email protected]:yourname/the-repo.git (push)
upstream https://github.com/theirname/the-repo.git (fetch)
upstream https://github.com/theirname/the-repo.git (push)

Now you have both the origin(Github forked repo) and upstream (original repo) available

To update your local repo to the original upstream repo – run

git fetch upstream

Then make sure then you are in your correct branch…

git checkout master

To merge your branch with the upstream repo branch, (change the word master if your branch is different) run…

git rebase upstream/master

Finally push the changes to the GitHub repo fork

git push -f origin master

This will then result in the GitHub fork branch being even with the original repo.

 

But I had Changes done on my local repo

If you had changes done on your local repo the rebase will fail, you’ll need to stash them, then rebase, then reapply them.

git stash
git rebase upstream/master
git stash apply

Then push to your origin master, although now as you had made changes your origin master will be ahead of the original repo.

You also will have to have SSH keys set up to allow passwordless connection – this is the guide here for that.

 

Ref

Cats: WebDev, Workflow Tags: git

Tags

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls

Donate a Beer to the Coolest Guides

Get Beaver Builder Now!

Discuss

3gs 10.6 apache backup baseband boot clean urls cpanel css curl custom database drupal el capitan git Google image instadmg ios iphone jailbreak keys lion mac macos mojave macos sierra menu mysql OSX panda php phpmyadmin private public redirect redsn0w remote rsa SEO shell ssh terminal unstoppables upgrade urls
Get DesktopServer

Lynda

Lynda.com Online Training Videos

TreeHouse

smlinks

Learn WordPress
osx-modify-shell-path

How to Add to the Shell Path in macOS Big Sur and Catalina using Terminal

October 19, 2019

virtual-hosts osx 10.10 yosemite

Set up Virtual Hosts on macOS Catalina 10.15 in Apache

October 19, 2019

Installing Homebrew on macOS Catalina 10.15, Package Manager for Linux Apps

October 18, 2019

Where is the bash shell in macos Catalina?

October 12, 2019

Refine your search

  • All
  • Modules
  • Themes
  • Documentation
  • Forums & Issues
  • Groups

RSS ars technica

  • Musi says evidence shows Apple conspired with music industry on App Store ban
  • Trump threatens Apple with 25% tariff to force iPhone manufacturing into US
  • I helped a lost dog’s AirTag ping its owner: An ode to replaceable batteries
  • Apple legend Jony Ive takes control of OpenAI’s design future
  • Epic goes to court to force Fortnite back on US iOS

RSS mac surfer

  • Tot is new text editor for Mac, iPhone, and iPad focused on constraints and ease of use
  • TiPbITS: Google Drive Sorting Can Hide New Documents
  • How to take a screenshot on a MacBook Pro
  • How To Create Simple Animation With Mac Keynote
  • Last Week on My Mac: Virus pandemics

Donate

Copyright © 2025· Neil Gee - All Rights Reserved - Hosted by Runcloud

Copyright © 2025 · gee on Genesis Framework · WordPress · Log in