DEV Community

Paul Caoile
Paul Caoile

Posted on

Github credentials for beginners

Control Panel

Photo by Jp Valery on Unsplash

Today I’m documenting how to enter your GitHub credentials only once for a certain period. This way, you can avoid the tedious operation of entering your username and password every time you push to your GitHub repo. This is especially helpful when you’re working on a remote computer or in the cloud. I do not want to have my password stored in a computer that I don’t own. I value security and by having it cache only for a certain period, gives me a little bit more piece of mind.

We will use a tool available in the Git CLI, called credential helpers. Git credentials authenticate the connection over non-SSH protocols. It informs Git to remember your username and password. Git ships with some default helpers that can be used to achieve this process, avoiding the tedious typing of your username and password when prompted every time you push to your Github repo.

  • Store – stores your credentials on disk protected only by file permissions.
  • Cache – stores your credentials in memory for a certain period.
  • Osxkeychain – if available, will use the OSX Keychain app to fetch the credentials. I believe this is used mostly on Mac.

I will only provide the instruction for cache as this is what I prefer to use. I will try and break down each parameter passed. You can also refer to this Github Help Doc in caching your Github password in Git.

Let’s get to this.

$ git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after an hour

$ git config = is the command used to set Git configuration values on either global or local level.

--global = means you want to apply this configuration to the user’s OS. Global configuration values are stored in a hidden file. One advantage of this is you don’t have to set it again when working with another project on your computer.

credential.helper = tells Git to remember your username and password every time it talks to Github.

‘cache –timeout=3600’ = will store your credentials for an hour.

Well, that is all for now. I will surely be coming back until I memorize this code.

Top comments (0)