Fork GitHub from the Command Line |Video upload date:  · Duration: PT5M2S  · Language: EN

Learn how to fork a GitHub repository from the command line using gh and git for fast collaboration and clean pull requests.

Get the gh CLI and sign in

First thing first you need the GitHub CLI on your laptop. Install the gh tool from the official source for your operating system then run gh auth login and answer the prompts. This will link your local shell to your GitHub account so you can pretend you are efficient.

Fork the repo from your shell

If you like living dangerously on the command line use gh to fork and optionally clone in one go. It looks like this

gh repo fork OWNER/REPO --clone

If you just want to create the fork and clone later omit the clone flag

gh repo fork OWNER/REPO

Clone your fork or point to upstream

Clone your fork with the URL you get after forking. Replace the placeholder with the actual clone URL from GitHub

git clone your-fork-url

If you already have a local copy of the original repository add an upstream remote so syncing stays sane

git remote add upstream original-repo-url

Create a branch commit and push

Do not work on master. That is how chaos is born. Create a feature branch and keep commits tidy

git checkout -b feature-name
# edit files
git add .
git commit -m 'Clear message'
git push origin feature-name

Open a pull request from the terminal

When your branch is pushed you can open a pull request without opening yet another browser tab

gh pr create --base master --head feature-name --fill

Follow the prompts to review the title and description then submit. If the project has a different default branch use that instead of master. Yes that happens.

Syncing your fork the boring but crucial part

Before you start a new feature fetch upstream and rebase so you do not invent merge conflicts for future you

git fetch upstream
git rebase upstream/master

Quick contributor checklist

  • Install and authenticate gh
  • Fork the repo and clone or add an upstream remote
  • Create a branch per feature
  • Commit with clear messages and push to origin
  • Open a PR with gh and follow contribution guidelines
  • Keep your fork synced with upstream

If you made it this far you deserve a cookie or at least the smug feeling of having used the command line to improve open source. Now go fix a bug and try not to break CI.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.