Skip to content

Instantly share code, notes, and snippets.

@Ryan1729
Created October 13, 2025 22:43
Show Gist options
  • Select an option

  • Save Ryan1729/3f4812ce79a255850a64fbf974541dcb to your computer and use it in GitHub Desktop.

Select an option

Save Ryan1729/3f4812ce79a255850a64fbf974541dcb to your computer and use it in GitHub Desktop.
Using the .git-credentials file with github tokens

This gist describes a method to set up git to read your github token from a file and automatically allow you to use commands like git push without eeding to provide the token every time.

You should understand that storing the token in plaintext in a relatively standard location could allow a savy adversary to steal it, and wreak havoc with your github account. But, hopefully you'd have the opportunity to revoke the token before they managed to do any harm, say after stealing your laptop.

Step 1. Create a github token

Follow these official instructions This has so far on;y been shown to work with classic tokens.

Step 2. Create a ~/.git-credentials file

In your home directory make a plain text file called .git-credentials and give it the following content

https://REPLACE_WITH_USERNAME:REPLACE_WITH_TOKEN@github.com

except of course, you should replace REPLACE_WITH_USERNAME with your github username and REPLACE_WITH_TOKEN with your token from step 1.

You can read more aobut this file here

Step 3. Set your repo to use the "store" helper

In the repo that you want run commands that interact with GitHub with, run git config credential.helper store. This updates a file in your .git folder.

You could probably also configure this globally if you like.

Running something like git push should now "just work", witohut asking you for a password at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment