Dev Minutes: How to set git config (username, email, and credentials)
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
- Locally for a single repository
- 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
- To save configs for local repository use
git config *variable name*
- To save globally use
--global
likegit config --global *variable name*
- To save credential in cache memory `
git config --global credential.helper cache