1028Setting up GitHub Command-Line Access

This is a short, condensed instruction how to set-up command-line access to github.com. Written is response to onboard new FabAcademy students - and get them started with MkDocs.

This guides is for macOS 12 or higher. My Mac uses macOS Ventura 13.0.01.

Step 1: Creating a new SSH Key

Go to the .ssh directory.

$ cd ~/.ssh

Made new key:

$ ssh-keygen -t ed25519 -C "your_email@example.com"
  • Don't just copy, put in your email. I also added a password.
  • Also, don't copy the $, just the ssh-keygen -t ed25519 -C "your_email@example.com" part. But with your email.

You can name your key. For this example, we call it id_github_test.

Step 2: Adding SSH Key to ssh-agent.

$ eval "$(ssh-agent -s)"

Step 3: Adding Key Info to config

Open .ssh/config in your favourite text editor. If you want to stay at the command line, use nano.

Add the following:

Host *.github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_github_test

Step 4: Adding the Key to ssh-agent

Adding private key to ssh-agent

$ ssh-add --apple-use-keychain ~/.ssh/id_github_test

This add the new key to the Apple Keychain.

If you used a passphrase when you created the key, you will be asked for it now.

Enter passphrase for /Users/georg/.ssh/id_github_test: 
Identity added: /Users/georg/.ssh/id_github_test (your_email@example.com)

Step 5: Adding Public Key to github.com

  • Log into Github
  • Profile > Settings > SSH and GPG Keys
  • Click 'New SSH Key'

Copy and paster your public key, in this example case, id_github_test.pub.

The tutorial on Github suggest to copy the public key using a command:

$ pbcopy < ~/.ssh/id_github_test.pub      

pbcopy - for paste board copy is the terminal interface to the macOS' Copy & Paste. pbcopy < read the content of a file into the copy memory. After running pbcopy you can press Command-V to paste the text.

  • Paste the copied SSH Public Key.

Step 5.1: Two-Factor Authentication at GitHub.com

I setup Two-Factor Authentication at GitHub.com, I had to confirm the addition of a new key via my mobile GitHub App. Your mileage might vary.

Step 6: Testing the connection

$ ssh -T git@github.com
Hi trembl! You've successfully authenticated, 
but GitHub does not provide shell access.

Ok, great! It worked!

Now you can clone, add, commit, push and pull!


1025hugo Shortcuts

Quick run through hugo Installation & Update on macOS.

Install hugo

brew install hugo

Check Version

hugo version

hugo v0.109.0+extended darwin/amd64 BuildDate=unknown

Upgrade hugo

brew upgrade hugo
Warning: hugo 0.109.0 already installed

Create New Site

hugo new site my-new-hugo-site
cd my-new-hugo-site
git init
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke themes/ananke
echo "theme = 'ananke'" >> config.toml

hugo does not come with an in-built theme, therefore we need to clone the anake theme into themes/ananke. More hugo themes. Clone and update config.toml.

Serve Site

hugo server

Build Site

Just hugo, nothing else.

Start building sites … 
hugo v0.109.0+extended darwin/amd64 BuildDate=unknown
INFO 2022/12/26 19:37:15 syncing static files to /

                   | EN  
  Pages            | 10  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  1  
  Processed images |  0  
  Aliases          |  1  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 154 ms

1024mkDocs Shortcuts

Quick run through mkDocs Installation & Update on macOS.

Install mkDocs

pip install mkdocs

Check Version

mkdocs -V

mkdocs, version 1.1.2 from /usr/local/lib/python3.9/site-packages/mkdocs (Python 3.9)

Update mkDocs

pip install -U mkdocs
mkdocs -V

mkdocs, version 1.4.2 from /usr/local/lib/python3.9/site-packages/mkdocs (Python 3.9)

Install mkdocs-material

pip install mkdocs-material

Update to latest mkdocs-material

pip install -U mkdocs-material

Create new mkDocs Site

mkdocs new my-new-site

Start Serving Site

cd my-new-site
mkdocs serve

Stop Serving Site

⌨️: ^[ctrl]-C

1002Rename Branches on GitHub

Renaming a branch on Github is straight-forward:

The "Lean More" link has some instructions how to update the local environments:

Your members will have to manually update their local environments. We'll let them know when they visit the repository, or you can share the following commands.

git branch -m oldbranchname newbranchname
git fetch origin

Username for 'https://github.com': trembl
Password for 'https://trembl@github.com': 

I tried automatically to log-in with my GitHub Password.

remote: Support for password authentication was removed on 
August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-
authentication-requirements-for-git-operations/ for more information.


Get a Personal Access Token

Ok, we need a Personal Access Token instead of the password!

Go to github.com > Settings > Developer Settings > Personal access tokens, and generate a new token with full repo access.

Once we use the token instead of the password, it works.

git branch -u origin/main main
# Branch 'main' set up to track remote branch 'main' from 'origin'.
git remote set-head origin -a
# origin/HEAD set to main

988Reset Local Git Repo

git reset --hard origin/main

main is the name your main branch.

976Git, Mac, SSH Keys and the OSX Keychain

When using git with a key that has a passphrase, you are asked the passphrase every time you pull/push. To make this a bit more convenient, add the key to the OSX Keychain.

Store key in OSX Keychain:

ssh-add -K ~/.ssh/my_key

Open .ssh/config

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/my_key

946Pulling a GitLab Repository with Tokens & Webhooks

Update from 864 Pulling a GitHub Repository with Tokens & Webhooks

GitLab requries a gitlab-ci-token: prefix:

$token = 'gitlab-ci-token:abcdefghijklmopq'

944Overwrite local changes with git pull

git pull does not overwrite any local changed files by default. If you want to overwrite - and loose - any local changes, use:

git reset --hard origin/main

origin/main might be origin/master for legacy repos.

864Pulling a GitHub Repository with Tokens & Webhooks

Here is how to sync a WordPress Theme from Github to your own server:

Create a Personal Access Token on GitHub

Webhook on GitHub:
Webhook on GitHub for .htaccess protected directory:
cd $temp_dir git init // initialize git git pull https://{$token}@github.com/{$repo}
<?php // path to local tmp directory $temp_dir = '/my/local/tmp/directory/'; // path to local theme directory $theme_dir = "/my/local/theme/directory/"; // access token from GitHub $token = 'abcdefghijk'; // Repo $repo = 'github.com/trembl/SuperNiceRepo.git'; // - - - - - // change to local git directory chdir($temp_dir); // resets local git echo exec('git reset --hard 2>&1') . ", "; // get latest from github echo exec("git pull https://$token@$repo 2>&1"); // delete theme dir echo "\n\nDeleting Theme Directory.\n"; echo exec("rm -rf $theme_dir*"); // * deletes all files within the directory // Copying Theme from $temp_dir to $theme_dir echo "\n\nCopying Theme from tmp folder to wp-content.\n"; echo exec("cp -a $temp_dir/* $theme_dir"); // cp -a $temp_dir/* copies everything _except_ invisible files, like .git ?> update.php protected by .htaccess? 860 Access a URL behind htaccess/htpasswd
Protect update.php ONLY with .htaccess? 940 Protecting a Single File with .htaccess

Q & A

I get the following error message: Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). That means git is not initalized. Run git init