Friday, 9 June 2017

storing git credentials

If you need to store git credentials so that you don't have to keep entering them when cloning a git repo over http(s)

Add the following to ~/.gitconfig
[user]
        email = bobmclarke@gmail.com
        name = Bob Clarke
[credential]
        helper = store

Then create ~/.git-credentials with the following contents
https://your-username:your-password@github.com

Now authentication to Git will work without prompting for credentials.

Another way of generating these files is to run:
git config --global user.email "bobmclarke@gmail.com"
git config --global user.name "Bob Clarke"
git config --global credential.helper store

Then push to the repo at which point you'll be prompted for your username and password. After you enter them for the first time a ~/.git-credentials file will be generated as above.

This can be useful if the developers in your team are using git as an npm repo for internal modules with something in the package.json like:
"some-npm-package-name": "git+https://github.com/bobclarke/mymodule#v1.0"

The downside is that your Git credentials will be stored in PLAIN TEXT so be aware.

Last thing to note, if you're doing this on an internal Github you may need to ignore ssl certs as follows:
git config --global http.sslVerify false





No comments:

Post a Comment