Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding GitHub token in .gitconfig

I would like to store all of my dotfiles on GitHub, including .gitconfig which requires me to hide the GitHub token in the .gitconfig.

To do so I have a ".gitconfig-hidden-token" file which is the file I intend to edit and put under git that hides the token:

...
[github]
user = giuliop
token = --hidden--
...

And a shell script which I need to launch if I modify the ".gitconfig-hidden-token" file to create the ".gitconfig" file:

cp .gitconfig .gitconfig.backup
sed 's/--hidden--/123456789/' .gitconfig-hidden-token > .gitconfig

The drawback is the need to manually launch the script everytime I modidy the file. Is there a better, fully automated way to do this?

like image 407
gws Avatar asked Dec 14 '11 13:12

gws


People also ask

Where is GitHub token stored?

Saving tokens in Linux The next time you are prompted for your GitHub user name and token, the information will be stored permanently in a . git-credentials file under your home folder.


2 Answers

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 = [email protected]
  token = a123uber456secret789ceprivate000key78

[credential]
  helper = osxkeychain
.gitignore:
/.gitconfig.local
like image 92
Dave Dopson Avatar answered Sep 20 '22 08:09

Dave Dopson


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.

like image 37
fge Avatar answered Sep 18 '22 08:09

fge