Dev Minutes: How to set git config (username, email, and credentials)

Umar Hayat
2 min readMay 31, 2021

Git is one of the most popular distributed version control systems used by almost all software companies.

One of the few things we mostly do on a newly set up machine is to install git and set its configurations.

There are two ways to set up git configs

  1. Locally for a single repository
  2. Globally for all git repository

Git configs for a single repository

To set up git configs for a single repository follow these commands.

cd ~/myproject

Set a Git username and email address:

git config user.name "engr-umar-hayat"
git config user.email "engr.umarhayat.rw@gmail.com"

To list down git configs on terminal

git config --list

Out of the command

The above git configurations are saved to .git/config . To display check if the above user name and email is there or not run

cat .git/config

Git global configs

To set your global commit name and email address run the git config command with the --global option:

git config --global user.name "engr-umar-hayat"
git config --global user.email "engr.umarhayat.rw@gmail.com"

Permanently authenticating with Git repository

If in case you are git HTTPS method instead of ssh then turn on the credential helper so that Git will save your password in memory for some time. And you will not be asked to enter git credential on every commit. By default, Git will cache your password for 15 minutes.

git config --global credential.helper cache
# Set git to use the credential memory cache

You should also specify caching expire,

git config --global credential.helper 'cache --timeout 7200'

Summary

  1. To save configs for local repository use git config *variable name*
  2. To save globally use --global likegit config --global *variable name*
  3. To save credential in cache memory `git config --global credential.helper cache

--

--

Umar Hayat

I am higly skilled python developer working on cutting edge technologies over past few years.