Creating a static website with GitHub Pages

I have a bunch of note as html files and want to easily host them somewhere. I’m looking into using GitHub Pages. GitHub pages provide themes, but for html files you need to add a header to the start of each file in markup format using Jekyll Front Matter.

layout: default

Add a sample test page with a couple of headers and you end up with a page rendered with your selected theme:

Access your site with the url: https://[your-github-user-id][repo-name]

Resetting a GitHub Personal Access Token on MacOS

Personal Access Token’s are used to grant access to one of your repos with specific permissions. They have an expiry, so when one expires you need to recreate a new one, details are here.

If you’re trying to push and your token has expired, you’ll see an error like this:

> git push
remote: Invalid username or password.
fatal: Authentication failed for '

The first time accessing a repo requiring authentication is simpler because it will prompt you for your id and password (or token). Once you’ve set one up though, it’s not as obvious how to reset a new token value, since the git cli only gives you the above error, it doesn’t prompt you to enter a new password/token.

To replace your cached credentials, use these steps (from here):

git config --global --unset credential.helper

git credential-osxkeychain erase

Press Return twice on the second step. Close your Terminal, open a new one, then:

git config --global "userid"
git config --global

From your GitHub account, go to Settings from the top right icon, then Developer Settings, then Personal Access Tokens.

Next time you do a push, use the Personal Access Token value when prompted for your password.

Re-writing previous git commits to change committer author/email

If you’ve committed a number of git commits using a wrong or value, you can re-write previous commits with:

git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "Old Name" ];
                git commit-tree "$@";
                git commit-tree "$@";
        fi' HEAD

Note that this will re-write all commits on the current branch matching the if condition which may or may not be what you’re looking for, so be careful. push the changes back to your remote origin as needed.

This is based on answers to this question here.

Moving a git ‘master’ branch to ‘main’

By default, the git install on my MacOS 11.5 creates new projects with a ‘master’ branch, but GitHub which I push to for my remote projects has been creating new projects with a default branch of ‘main’ for some time now.

To move a master branch to main locally, set it as the default branch and then push to GitHub I use the following steps (taken from multiple places but mainly from this article):

Create a new main branch from master locally:

git branch -m master main

Add remote GitHub repo:

git remote add github https://your-repo-url

Pull remote changes from remote main branch

git pull github main

Set upstream branch to track main

git branch  --set-upstream-to github/main

Push local to github main

git push github main

If you have changes in the new remote project (like a readme) that don’t exist locally yet and you get the error: “fatal: refusing to merge unrelated histories” then pull with the allow unrelated histories option:

git pull github master --allow-unrelated-histories

Now:’git push’ and you should be good.

For my local development these steps are enough for what I need, but if you have a master in your remote repo too and want to delete it there are additional steps in the article linked above.