Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

My github credential for git

A few years ago, Github decided passwords were not good enough, and made me use a static password that must be stored somewhere on the filesystem. How is that better than a password I type every ~hour?

So here's how I automated it so I never have to cat token-github for pasting into the auth form when pushing to the cruddy old github. I push changes there only for projects that already exist there; I don't use github for my own projects.

You set up ~/.gitconfig like so.

[includeIf "hasconfig:remote.*.url:https://github.com/**"]
   path = ~/.gitconfig-github

And then ~/.gitconfig-github like the following.

# References:
#    man git-config
#    https://medium.com/@jogarcia/different-git-configurations-for-different-remote-repositories-276759c4f14c
[core]
   askPass = /home/bgstack15/.gitconfig-github.sh
[credential]
   username = bgstack15

And then finally ~/.gitconfig-github.sh.

#!/bin/sh
cat /path/to/token-github

I didn't want to deal with how git might parse spaces in askPass=, so it was logical to use a shell script.

And now Github gets what it wants (a password stored somewhere on the filesystem), and I get what I want (auth without copy-pasting).

References

  1. Different git configurations for different remote repositories | by Jose Garcia | Medium

Comments