
config are files that store Git configurations, there are three files that are used to define configurations at three different levels,
- Local
- Global
- System
1. --local git config file:
📁 local file location: Inside the root directory of your repository.
Example: /<repo-name>/.git/config
Let's consider myrepo is the repo I created locally using the git init command,
# cd myrepo
# ls -la
total 68
drwxr-xr-x 4 root root 4096 Aug 25 02:00 .
drwxr-xr-x 1 root root 4096 Aug 24 00:42 ..
drwxr-xr-x 8 root root 4096 Aug 24 10:33 .git
-rw-r--r-- 1 root root 14 Aug 20 14:12 .gitignore
....
-rw-r--r-- 1 root root 1058 Aug 25 02:00 dynamo-db.txt
-rw-r--r-- 1 root root 4652 Aug 21 04:50 git-notes.txt
-rw-r--r-- 1 root root 6324 Aug 20 13:52 s3-notes.txt
# cd .git
# ls -l
total 48
-rw-r--r-- 1 root root 18 Aug 24 10:33 COMMIT_EDITMSG
-rw-r--r-- 1 root root 0 Aug 21 03:44 FETCH_HEAD
-rw-r--r-- 1 root root 21 Aug 17 03:56 HEAD
-rw-r--r-- 1 root root 41 Aug 19 07:41 ORIG_HEAD
drwxr-xr-x 2 root root 4096 Aug 17 03:56 branches
-rw-r--r-- 1 root root 320 Aug 21 03:48 config
-rw-r--r-- 1 root root 73 Aug 17 03:56 description
drwxr-xr-x 2 root root 4096 Aug 17 03:56 hooks
-rw-r--r-- 1 root root 916 Aug 24 10:33 index
drwxr-xr-x 2 root root 4096 Aug 17 03:56 info
drwxr-xr-x 3 root root 4096 Aug 17 03:58 logs
drwxr-xr-x 68 root root 4096 Aug 24 10:33 objects
drwxr-xr-x 5 root root 4096 Aug 17 03:59 refs
# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = https://..../mynotes.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
If you do not provide any options along with git config command, the action will be performed against the local config file.
2. --global git config file:
📁 global file location: Inside the root directory of your user.
on macOS/Unix/Linux/Ubuntu: ~/.gitconfig
on Windows: C:\<user-folder>\.gitconfig
As you may have guessed, the global config file is used to write user-specific configurations.
3. --system git config file:
📁 system file location: Inside the root directory of your system.
on macOS/Unix/Linux/Ubuntu: /etc/gitconfig
on Windows: C:\Documents and Settings\All Users\Application Data\Git\config
The configurations set at the system level are applicable to all users within the system and all the git repositories.
Git config commands and options
usage: git config [--options]
--list option: git config --list
The --list option will display all the configuration values from global and system (and local if you are running the command from within a local repo)
% git config --list core.repositoryformatversion=0 core.filemode=true core.bare=false core.logallrefupdates=true
Add another option --show-origin to even display from where these properties are displayed, it could show that you may have set the same property in multiple levels with the same name.
See list from the local config file:% git config --list --show-origin file:/etc/gitconfig system.message=hello-system file:/root/.gitconfig global.message=hello-global file:.git/config core.repositoryformatversion=0 file:.git/config core.filemode=true file:.git/config core.bare=false file:.git/config core.logallrefupdates=true file:.git/config local.message=hello-local
See list from the global config file:% git config --list --local --show-origin file:.git/config core.repositoryformatversion=0 file:.git/config core.filemode=true file:.git/config core.bare=false file:.git/config core.logallrefupdates=true file:.git/config local.message=hello-local
See list from the system config file:% git config --list --global --show-origin file:/root/.gitconfig global.message=hello-global
% git config --list --system --show-origin file:/etc/gitconfig system.message=hello-system
View & Set a values using git config:
View value example:% git config section.key value
% git config env.name --local
Note: If you do not pass any level details (global/local/system), the values will be set at the local level, provided you are within your repo.
Below are the first commands that you would need to execute to set the email and user values before you can commit your first code.
Set value example:
Example: Setting your default git editor:% git config --global user.email "you@example.com" % git config --global user.name "Your Name"
Example: Setting your default git merge tool:% git config --global core.editor "nano -w"
Example: Create alias:% git config --global merge.tool kdiff3
Set a boolean value:% git config --global alias.ci commit
Set an int value:% git config --bool env.isStage true
Add new values without altering any existing ones:% git config --int env.num 2
% git config --add sample.name Chris
% git config --add sample.name Mike
% git config --add sample.name Sam
% git config sample.name Chris Mike Sam
--unset: Remove the set config values:
% git config --unset env.name
To remove a set value make use of the --unset option.
--unset: will remove the first matching value of the key.
--unset-all: will remove all matching values of the key.
Example: Unset global value% git config --unset --global env.message
--edit: Edit the config files in editor:
In order to edit the text contents of the config files, you do not need to know the location of the files, you can simply use the --edit option along with the global, local and system options, it should open you set editor to edit the text,
Edit local config file:% git config --local --edit Opens Nano for me: core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [local] message = hello-local [section] key = value [a] isBool = true [env] no1 = 1 no2 = 2
Note: You must be within the repo to run this command.
Edit global config file:
Edit system config file:% git config --global --edit
% git config --system --edit
--add -- add new value without altering any existing ones
--blob -- read config from given blob object
--bool -- setting is a boolean
--bool-or-int --int -- setting is an integer
--default -- with --get, use specified default value when entry is missing
--edit -- open config file for editing
--expiry-date -- setting is an expiry date
--file -- use given config file
--get -- get the first matching value of the key
--get-all -- get all matching values of the key
--get-color -- find color setting
--get-colorbool -- check if color should be used
--get-regexp -- like "--get-all", but interpret "name" as a regular expression
--get-urlmatch -- get value specific for the URL
--global -- use user-global config file
--includes -- respect "include.*" directives in config files when looking up values
--list -- list all variables set in config file
--local -- use local config file
--name-only -- show variable names only
--no-includes -- don't respect "include.*" directives
--null -- end values with NUL and newline between key and value
--path -- setting is a path
--remove-section -- remove the given section
--rename-section -- rename the given section
--replace-all -- replace all values of the given key
--show-origin -- show origin of config
--system -- use system-wide config file
--type -- ensure that incoming and outgoing values are canonicalize-able as the given typ
--unset -- remove the first matching value of the key
--unset-all -- remove all matching values of the key
--worktree -- use per-worktree config file
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- Github: How to Invite Collaborators
- Git Commit - Author identity unknown, Please tell me who you are email
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- Get List of all local branches git command
- Git Revision Questions Before the Interview
- git fatal: Authentication failed error [fix]
- How to Install Git on Ubuntu Linux
- GitHub: How to Search Code
- How to change Git Default Author and Committer details in Eclipse
- How to check your installed version of Git
- Install GitHub Command Line Tool on Mac
- How to Merge Branch into Master Branch
- Perform an Empty Commit in Git without anything in Staging Area
- Git Fix: fatal: refusing to merge unrelated histories Error
- How to undo last Git Commit on Local Repository?
- git command to remove/unstage files from staging area
- Step-by-Step: Setting up Docker + Ubuntu Linux + Git + GitHub Tutorial
- Remove git config at Local, Global or System Levels?
- Fix [oh-my-zsh] Cant update: not a git repository
- Git Config Command - A Deep Dive
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- How to change directory in Git bash
- How to create volume in Docker using Command - Docker
- The default interactive shell is now zsh. [macOS] - MacOS
- How to serialize-deserialize an object in java - Java
- How to find files taking up space on your Mac - MacOS
- [fix] MySQL cj jdbc CommunicationsException: Communications link failure - Java
- Get Button Text onClick Android App - Android
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error - Android
- Eclipse Error The JVM Shared Library JavaVirtualMachines does not contain the JNI_CreateJavaVM symbol - Eclipse