Git Useful Commands, and Tricks

Save GitHub credentials and automatically fill them in

Enterprises will require you to generate a GitHub token, and use that instead of a password when you clone or push to an enterprise GitHub repository. It's daunting to enter credentials manually. One way is to only save your token as an environment variable, and when git prompts you, call that env variable. But this is cumbersome and faulty. The better and more secure way is to have it filled in automatically, and here's how.

Add the following lines to your ~/.gitconfig file. If you don't have it, create it.

[user]
        email = your_email@website.com
        name = Your Name
[credential]
        helper = "!f() { sleep 1; echo \"username=${USER}\"; echo \"password=${GIT_TOKEN}\"; }; f"

Where ${USER} and ${GIT_TOKEN} are the environment variables where you saved your username and GitHub token.

Last updated