10x your GIT workflow with this simple shortcut

bshelling
3 min readMar 2, 2024
Photo by James Harrison on Unsplash

In the last year I’ve become more inclined to wrap my most common cli commands in shell scripts. One command being git push.
Like many developers I use Github as a version control service provider and as you may know Github now requires an access token for all git api tranactions.
In 2022 Github introduced Fine-grained personal access tokens. These tokens give users more control as to how their able to interact with their account and Github via the api with a more role-based access control/ least privilege approach. Read more about fine-grained persona access tokens.

The common pattern for committing to files to a repo is as follows

git commit pre fine-grained token

From the example git push origin [branch] up until 2022 basic auth (i.e. username/password) was necessary to execute. Even though Github allows users to use classic tokens they recommend fine-grained access tokens.

So now with fine-grained access tokens auth is done as an connection string. Pushing to a repo will look like this.

git commit fine-grained token

As a developer the number of keystrokes in the cli should come at a premium and depending on the environment’s security requirements the access token expires a little as 7 days.
Because of this I created a shortcut where new tokens are can be easily replace from a shell script and the script executes using a single command.
*Note — The shortcut only applies to the push command but can expanded to include the add and commit commands.

The shortcut

Create a shell file, within the fill declare 3 variables, GITKEY, GITPATH, and GITURL. The access token assigned to GITKEY, your github account url with the cli argurment value assigned to GITPATH and the auth url is assigned to GITURL. GITURL is then passed to the git push command as argument.

To make the script an executable command apply a symlink to the file path. In the example below the file is given a command name of deploy and the branch name is passed as an argument. From this point on less keystrokes and when the token expires it can be renewed by replacing it for the new one in the file.

An example of a symlink to the shell script

--

--

bshelling

Shelling is what they call me. A forward thinker debugging life's code line by line. Creator, crossfitter, developer, engineer