/
๐Ÿ“

Github Tips

https://github.blog/2020-04-09-github-protips-tips-tricks-hacks-and-secrets-from-lee-reilly/
githubgitshellcli
On this page

Set up and use multiple GitHub accounts on the same computer

  1. Create separate SSH keys for each GitHub account:
sh
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"

Save each key with a unique name (e.g., id_rsa_personal, id_rsa_work).

  1. Add the SSH keys to the SSH agent:
sh
ssh-add ~/.ssh/id_rsa_personal
ssh-add ~/.ssh/id_rsa_work
  1. Add SSH Keys to GitHub

Copy the public key contents:

sh
cat ~/.ssh/id_rsa_personal.pub

Add the public key to each respective GitHub account in the SSH and GPG keys settings.

  1. Create or edit the SSH config file:
sh
nano ~/.ssh/config
txt
# Personal account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# Work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
  1. For each repository, set the appropriate user name and email:
sh
git config user.name "Your Name"
git config user.email "your-email@example.com"
  1. Clone and Use Repositories
sh
git clone git@github.com-personal:username/repo.git
git clone git@github.com-work:username/repo.git
# For existing repositories, update the remote URL:
git remote set-url origin git@github.com-personal:username/repo.git

Defaults for Github repositories

Connect local npm to the GitHub Package Registry

sh
npm login --registry=https://npm.pkg.github.com

๐Ÿ’ก Enter your GitHub user info. Username is your GitHub user name. When using 2FA, password is your applicable personal access token.

๐Ÿ’ก Make sure your personal access token has the ability to read from GitHub Package Registry.

GitHub Web Editor

Open in github.dev editor by pressing the . (period).

Keyboard Shortcut

octokit.js

The all-batteries included GitHub SDK for Browsers, Node.js, and Deno.

GitHub Pages

GitHub Pages is designed to host your personal, organization, or project pages from a GitHub repository.

GitHub Pages is disabled by default, endable it in each repository's setting

Cli

gh is GitHub on the command line. It brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working with git and your code.

sh
brew install gh
brew upgrade gh
gh auth login
gh config set git_protocol ssh

Set Secrets

sh
gh secret set EMAIL_USERNAME -b""
gh secret set EMAIL_PASSWORD -b""
gh secret set SLACK_WEBHOOK_URL -b""

Note: get slack webhook url from here

Work with fuzzy-finder tools such as fzf

sh
brew install fzf
gh pr list | fzf

Note: The fzf utility allows interactively filtering the input stream and prints the selected line as its output.

Github Readme Stats

Top Langs

Supported by the GitHub Readme Stats

Awesome-Profile-README-templates

-Example

Tips

One second to read GitHub code with VS Code

Just add 1s after github and press Enter in the browser address bar for any repository you want to read.

Code Suggestions

suggestion
# Change line

๐Ÿ”Ž Fuzzy file finder

Press t in any repository to access it and start typing the name of the file you want to find.

Linking to code snippets

To add a code snippet: select the lines you want to reference, open the inline toolbar, click Copy permalink, and paste it anywhere.

Markdown formatting tips

[!NOTE] Highlights information that users should take into account, even when skimming.

[!TIP] Optional information to help a user be more successful.

[!IMPORTANT] Crucial information necessary for users to succeed.

[!WARNING] Critical content demanding immediate user attention due to potential risks.

[!CAUTION] Negative potential consequences of an action.

Keyboard tags

html
Press <kbd>W</kbd> to go up, and <kbd>A</kbd> to go down. If you can find the
<kbd>ESC</kbd>, pressing that will fire missiles ๐Ÿš€

Visualizing hex codes

Placing hex colors in backticks renders a tile in that color.

sh
GitHub contribution graph colors: `#C6E48B` `#7AC96F` `#249A3C` `#196127`

Visualizing diffs

diff
10 PRINT โ€œBASIC IS COOLโ€
- 20 GOTO 11
+ 20 GOTO 10

Centering text and images

html
<div align="center">
<img src="https://octodex.github.com/images/dunetocat.png" width="200" />
<p>This is some centered text.</p>
</div>
<div align="center">
<img src="https://octodex.github.com/images/dunetocat.png" width="200" />
<p>This is some centered text.</p>
</div>

Inserting a video

IMAGE ALT TEXT HERE
html
<a
href="http://www.youtube.com/watch?feature=player_embedded&v=YOUTUBE_VIDEO_ID_HERE
"
target="_blank"
><img
src="http://img.youtube.com/vi/YOUTUBE_VIDEO_ID_HERE/0.jpg"
alt="IMAGE ALT TEXT HERE"
width="240"
height="180"
border="10"
/></a>

Inserting a table

Online tool to convert other formats to markdown table

TypeBattery-powered End DeviceAlways-on End DeviceIoT GatewayCloud Backend Traditional
Traditional IoTSensor with Custom ProtocolSensor with Custom ProtocolTransparent ProxyCentralized Core Services
Blockchain IoTServer-trusting Client or Sensor with Custom ProtocolThin Client or Server-trusting ClientFull Node or Thin ClientMiners and Full Nodes

Inserting a table with html

html
<table>
<tr>
<th width="50%">
<a title="show-whitespace"></a> Show whitespace characters.
</th>
<th width="50%">Adds one-click merge conflict fixers</th>
</tr>
<tr>
<!-- Prevent zebra stripes -->
</tr>
<tr>
<td>
<img
src="https://user-images.githubusercontent.com/1402241/61187598-f9118380-a6a5-11e9-985a-990a7f798805.png"
/>
</td>
<td>
<img
src="https://user-images.githubusercontent.com/1402241/54978791-45906080-4fdc-11e9-8fe1-45374f8ff636.png"
/>
</td>
</tr>
</table>

Delete a bunch of Github Repositories

sh
#!/bin/sh
# Delete a bunch of GitHub repos
nukem="repo1 repo2"
user=""
password_or_oauth_token=""
for repo in $nukem; do
echo "Deleting https://github.com/repos/$user/$repo"
curl -v -u "$user:$password_or_oauth_token" -X DELETE \
"https://api.github.com/repos/$user/$repo"
done

Count total files

sh
git ls-files $notes | wc -l

Count diff files

sh
git diff --name-only "@{1 day ago}" $notes | wc -l

Workflows

Extensions

Browser extension that simplifies the GitHub interface and adds useful features

Browser extension that enhances GitHub code review and exploration.

Tutorials

Resources

HelloGitHub is sharing interesting, entry-level open source projects on GitHub.

The official GitHub REST API v3.

Edit this page
logo
Code-related notes and snippets