Files
mintlify__docs/git/config.mdx
2026-02-09 20:46:44 +00:00

351 lines
5.8 KiB
Plaintext

---
title: git config
description: Get and set repository or global options
---
Configure Git settings for your user, repository, or system.
## Syntax
```bash
git config [options] <name> [<value>]
```
## Description
`git config` manages Git configuration variables that control how Git looks and operates. Configuration can be set at three levels: system, global (user), and local (repository).
## Common usage
Set your name:
```bash
git config --global user.name "Your Name"
```
Set your email:
```bash
git config --global user.email "your.email@example.com"
```
View a setting:
```bash
git config user.name
```
## Configuration levels
<ParamField path="--system" type="flag">
System-wide settings for all users
```bash
git config --system <setting>
```
</ParamField>
<ParamField path="--global" type="flag">
User-specific settings
```bash
git config --global <setting>
```
</ParamField>
<ParamField path="--local" type="flag">
Repository-specific settings (default)
```bash
git config --local <setting>
```
</ParamField>
## Essential configuration
### Identity
Set your name and email (required for commits):
```bash
git config --global user.name "Jane Doe"
git config --global user.email "jane@example.com"
```
### Default branch
Set default branch name for new repositories:
```bash
git config --global init.defaultBranch main
```
### Default editor
Set your preferred text editor:
```bash
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # Vim
git config --global core.editor "nano" # Nano
```
## Options
<ParamField path="--list" type="flag">
List all configuration settings
```bash
git config --list
```
</ParamField>
<ParamField path="--unset" type="flag">
Remove a configuration setting
```bash
git config --unset user.email
```
</ParamField>
<ParamField path="--get" type="flag">
Get value of a setting
```bash
git config --get user.name
```
</ParamField>
## Examples
### View all settings
```bash
git config --list
```
### View global settings
```bash
git config --global --list
```
### View specific setting
```bash
git config user.email
```
### Set credential helper
```bash
# macOS
git config --global credential.helper osxkeychain
# Windows
git config --global credential.helper wincred
# Linux
git config --global credential.helper cache
```
### Configure line endings
```bash
# Windows
git config --global core.autocrlf true
# macOS/Linux
git config --global core.autocrlf input
```
### Set default pull behavior
```bash
git config --global pull.rebase false # Merge (default)
git config --global pull.rebase true # Rebase
```
## Common configurations
### User information
```bash
git config --global user.name "Your Name"
git config --global user.email "email@example.com"
```
### Aliases
Create shortcuts for common commands:
```bash
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.lg 'log --graph --oneline --all'
```
Use aliases:
```bash
git co main # git checkout main
git st # git status
git lg # git log --graph --oneline --all
```
### Colors
Enable colored output:
```bash
git config --global color.ui auto
```
### Diff and merge tools
```bash
git config --global diff.tool vscode
git config --global merge.tool vscode
```
## Configuration file locations
### Global config
- Linux/macOS: `~/.gitconfig`
- Windows: `C:\Users\<username>\.gitconfig`
### Repository config
- `.git/config` in repository root
### System config
- Linux: `/etc/gitconfig`
- Windows: `C:\ProgramData\Git\config`
## Viewing configuration
### All settings with origins
```bash
git config --list --show-origin
```
Shows where each setting is defined.
### Edit config file directly
```bash
# Edit global config
git config --global --edit
# Edit repository config
git config --edit
```
## Removing settings
### Remove specific setting
```bash
git config --global --unset user.email
```
### Remove section
```bash
git config --global --remove-section user
```
## Advanced configuration
### Ignore file permissions
```bash
git config core.fileMode false
```
### Set push default
```bash
git config --global push.default current
```
### Configure rerere
Reuse recorded resolution of conflicts:
```bash
git config --global rerere.enabled true
```
### Set fetch prune
Automatically prune on fetch:
```bash
git config --global fetch.prune true
```
## Useful aliases
```bash
# Status shortcut
git config --global alias.s 'status -s'
# Pretty log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# Undo last commit
git config --global alias.undo 'reset HEAD~1 --mixed'
# Amend without editing message
git config --global alias.amend 'commit --amend --no-edit'
```
## Best practices
- Always configure `user.name` and `user.email`
- Use global config for personal preferences
- Use local config for project-specific settings
- Create aliases for frequently used commands
- Enable credential caching for convenience
- Configure line endings based on your OS
- Set default branch name to `main`
## Troubleshooting
### Check effective configuration
```bash
git config --list --show-origin
```
### Reset to defaults
```bash
# Remove global config
rm ~/.gitconfig
# Or remove specific settings
git config --global --unset-all user.name
```
### Verify settings
```bash
git config --get user.name
git config --get user.email
```
## Related commands
- [git init](/git/init) - Initialize repository
- [git clone](/git/clone) - Clone repository
- [git help](/git/help) - Get help with Git