Updating Personal Access Tokens used with Github Actions

A while back I set up a Github Action to build and deploy an app on each code commit. Since it’s good practice to set an expiry date on your Personal Access Tokens, at some point they will expire and you’ll need to update them.

In my project I reference the Access Token using a Github Secret stored in the settings for the project:

To update the expired or about to expire token:

  • create a new Personal Access Token in your account settings
  • copy the new token value, update the Secrets in your project and paste the new value

Done!

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

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

git filter-branch --commit-filter '
        if [ "$GIT_COMMITTER_NAME" = "Old Name" ];
        then
                GIT_COMMITTER_NAME="new-name";
                GIT_AUTHOR_NAME="new-name";
                GIT_COMMITTER_EMAIL="new-email";
                GIT_AUTHOR_EMAIL="new-email";
                git commit-tree "$@";
        else
                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.