Joshua's Cheatsheets - Github Cheatsheet, Notes, and Tips
Light
help

Resources

What & Link Type
My Git Cheat Sheet Cheat Sheet
Github Help: Homepage Official Docs
Good Cheatsheet: tiimgreen/github-cheat-sheet Cheatsheet
Collection of cool Github resources: awesome-github Collection
Helpful browser extensions Collection

Your Github Profile

You can now customize your Github profile by creating a repo with the same name as your username, and editing README.md with the content you want. For more details, follow this handy guide.

Here is my profile 👨‍💻 😊

Tips and Tricks

Misc

  • Get the size of a repo before cloning / forking /etc.

    • There is an API endpoint you can use to get repo info, including size. No login / creds required for public repos!

      • https://api.github.com/repos/{owner}/{repoName}
      • You can use a browser, cURL, or your fetcher of choice, then look for .size, which is in KB.

Searching Github

Docs:

Tips:

  • You can search across all your own code, by filtering by your own username, with user:{your username}
  • You need to be logged in for many of the advanced search filters and code search
  • Sometimes languages don't show up in the language selector, but are still "filterable" via query string manipulation

Badges

Ultimate one-stop-shop for finding badges - shields.io

Some of my favorite badges / most used:

  • Glitch Badges

    • From your project editor, you can find remix links and images by using Share -> Share Buttons
    • One official remix SVG URL is https://cdn.gomix.com/f3620a78-0ad3-4f81-a271-c8a4faa20f86%2Fremix-button.svg
    • For more details:

  • CodeCov:

    • URL: https://codecov.io/gh/{USER}/{REPO}/branch/{BRANCH}/graph/badge.svg
    • MD: [![Code Coverage Badge](https://codecov.io/gh/{USER}/{REPO}/branch/{BRANCH}/graph/badge.svg)](https://codecov.io/gh/{USER}/{REPO}/branch/{BRANCH})
  • NPM:

    • MD: [![NPM Badge](https://img.shields.io/npm/v/{PKG_NAME})](https://www.npmjs.com/package/{PKG_NAME})
  • Git tag version:

    • ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/{USER}/{REPO})

Don't forget; you can link your badge to a webpage! In markdown, use [![Badge Alt Text](Badge_URL)](Link on badge click)

PRs (Pull-Requests)

Special Diffing Views

There are some special diff / comparison URLs for Github - check out "Things you didn't know you could diff in Github"

Dealing with PRs Locally - Method A

The best way, although maybe not the fastest, to deal with a PR locally is to set up a new local branch that tracks to the PR's branch - this is not so straightforward if the PR is for a forked repo.

Having a tracked branch will also allow you to push commits to the PR author's branch, assuming that they left the box checked that says "allow edits from maintainers".

In the case that the PR is to merge a branch from a fork (as is common with open-source work), here is what you need to do:

  1. Add the forked repo as a remote

    • git remote add {alias_for_fork} {fork_full_repo_url.git}
  2. Get the data from the new remote

    • git fetch {alias_for_fork}
  3. Now, you can either checkout their branch directly, or make a branch to track their branch:

    • Directly checkout: git checkout {alias_for_fork}/{pr_branch_name}
    • Via tracking branch: git checkout -b {mirror_branch_name} {alias_for_fork}/{pr_branch_name}

      • Example: git checkout -b fred-master fred/master

If you want to add a commit to their PR branch, simply add the new commit to your tracking branch, and then:

  • If you checked the branch out directly, simply use git push
  • If you are using a "mirror" branch, use git push {alias_for_fork} HEAD:{pr_branch_name}

    • The git CLI should automatically prompt you to do this if you forget and try to just use push without options (it will throw a fatal: the upstream branch does not match the name of your current branch)

Dealing with PRs locally - Method B

A faster way to interact with and git checkout a PR locally, even before any of it is merged, by using this:

git fetch origin pull/{PR_NUMBER}/head:{LOCAL_BRANCH_TO_CREATE}

For example:

git fetch origin pull/4/head:pr-4

Just replace the PR # with the one you want!

For updating your local branch after the PR has been updated, you can use git pull origin pull/{PR_NUMBER}/head

For details, see this breakdown on how the command works

Keyboard Shortcuts!

Key Shortcut
? See all shortcuts!!! (also, here)
y Get page permalink (aka canonical link)
s or / Focus the search bar
CTRL + SHIFT + P Toggle between write and preview mode (markdown)

Github Actions and Workflows

Resources

FAQ

  • Workflows vs actions?

    • Workflows are at the highest level of Github Actions - a workflow can contain all the sub-components of Github Automation pieces
    • Workflow -> [Job] -> [Step] -> [Action (GH, or Docker), Task, or Command]
    • The best diagram I have found (so far) that clearly shows this, is this one, from this article.
  • How do I get a nice badge image based on actions?

    • Docs: Adding a workflow status badge
    • Summary: The URL syntax is one of...:

      • If workflow has name: https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_NAME>/badge.svg
      • If no name field: https://github.com/<OWNER>/<REPOSITORY>/workflows/<WORKFLOW_FILE_PATH>/badge.svg
    • Remember URL encoding
  • How do I use secrets / passwords / .env vars?

    1. Add them under Repo -> Settings -> Secrets
    2. Within a workflow .yml file, pull in the secret with this syntax:

      • ${{ secrets.SECRET_NAME }}

Markdown Source Last Updated:
Fri Sep 04 2020 00:49:53 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Tue Mar 10 2020 13:32:10 GMT+0000 (Coordinated Universal Time)
© 2020 Joshua Tzucker, Built with Gatsby