Hiding GitHub token in .gitconfig Hiding GitHub token in .gitconfig linux linux

Hiding GitHub token in .gitconfig


I just fixed this up for myself. The "proper" way to solve the issue is to split your gitconfig into two files, a public one with the alias/config/etc, and a private file that keeps your username and secrets. Like so...


From https://github.com/ddopson/dotfiles ...

.gitconfig:
[include]  # For username / creds / etc  path = ~/.gitconfig.local[alias]  ... 
.gitconfig.local:
[user]  user = ddopson  name = Dave Dopson  email = ddopson@gmail.com  token = a123uber456secret789ceprivate000key78[credential]  helper = osxkeychain
.gitignore:
/.gitconfig.local


Add your .gitconfig with git add -N.

Then git add -p it, edit the hunk, replace the token with anything, and push that. No need for an extra file this way.

Addendum: on additional modifications of your file, use git add -p again, and edit the hunk so that your initial manipulation not be overwritten.


You can now include another file in your gitconfig. You could put your github section in that extra file. See this question: Is it possible to include a file in your .gitconfig