Git Configuration
Table of contents
- Configuration levels
- Identity configuration
- Editor configuration
- SSH configuration
- Other useful configurations
- Verifying the configuration
1 - Configuration levels
Git uses three configuration levels:
| Level | Scope | File | Option |
|---|---|---|---|
| System | All users | /etc/gitconfig | --system |
| Global | Your user | ~/.gitconfig | --global |
| Local | A single repository | .git/config | --local |
💡 Priority: Local > Global > System (the most specific wins)
View the current configuration
# Toute la configuration
git config --list
# Configuration globale uniquement
git config --global --list
# Origine de chaque paramètre
git config --list --show-origin
🔝 Back to table of contents
2 - Identity configuration
2.1 Configure your name and email
This is MANDATORY before making your first commit!
git config --global user.name "Votre Nom"
git config --global user.email "[email protected]"
⚠️ Important: Use the same email as your GitHub account so your contributions are correctly attributed.
2.2 Verify the configuration
git config user.name
git config user.email
2.3 Per-project configuration (optional)
If you work with different identities (personal/professional):
# Dans le dossier du projet
cd mon-projet-pro
git config --local user.name "Jean Dupont"
git config --local user.email "[email protected]"
🔝 Back to table of contents
3 - Editor configuration
3.1 Set the default editor
The editor is used to write commit messages and resolve conflicts.
Visual Studio Code (recommended):
git config --global core.editor "code --wait"
Vim:
git config --global core.editor "vim"
Nano:
git config --global core.editor "nano"
Notepad++ (Windows):
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
Sublime Text:
git config --global core.editor "subl -n -w"
3.2 Verify the configured editor
git config core.editor
🔝 Back to table of contents
4 - SSH configuration
4.1 Why SSH?
| Method | Advantages | Drawbacks |
|---|---|---|
| HTTPS | Simple to set up | Prompts for password |
| SSH | No password, more secure | Initial setup required |
4.2 Check for existing keys
ls -la ~/.ssh
Look for files like id_ed25519, id_rsa, etc.
4.3 Generate a new SSH key
Ed25519 key (recommended):
ssh-keygen -t ed25519 -C "[email protected]"
If Ed25519 is not supported, use RSA:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
4.4 Answers to the prompts
Enter file in which to save the key (/home/user/.ssh/id_ed25519): [Appuyez Entrée]
Enter passphrase (empty for no passphrase): [Entrez un mot de passe ou Entrée]
Enter same passphrase again: [Confirmez]
💡 Tip: Add a passphrase for extra security!
4.5 Add the key to the SSH agent
Linux/macOS:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Windows (Git Bash):
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_ed25519
4.6 Copy the public key
Linux:
cat ~/.ssh/id_ed25519.pub
macOS:
pbcopy < ~/.ssh/id_ed25519.pub
Windows (Git Bash):
clip < ~/.ssh/id_ed25519.pub
4.7 Add the key to GitHub
- Go to GitHub → Settings → SSH and GPG keys
- Click New SSH key
- Title: A descriptive name (e.g., "Personal MacBook Pro")
- Key type: Authentication Key
- Key: Paste your public key
- Click Add SSH key
4.8 Test the connection
ssh -T [email protected]
Expected result:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
🔝 Back to table of contents
5 - Other useful configurations
5.1 Default branch
git config --global init.defaultBranch main
5.2 Line ending management
Windows:
git config --global core.autocrlf true
macOS/Linux:
git config --global core.autocrlf input
5.3 Colors in the terminal
git config --global color.ui auto
5.4 Aliases (shortcuts)
Create shortcuts for frequent commands:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.lg "log --oneline --graph --all"
Usage:
git st # équivalent à git status
git co main # équivalent à git checkout main
git lg # log graphique
5.5 Pull configuration
# Éviter les merges automatiques lors d'un pull
git config --global pull.rebase false
# Ou préférer le rebase
git config --global pull.rebase true
5.6 Credential helper (remember your credentials)
Windows:
git config --global credential.helper manager
macOS:
git config --global credential.helper osxkeychain
Linux:
git config --global credential.helper cache --timeout=3600
🔝 Back to table of contents
6 - Verifying the configuration
6.1 View the entire configuration
git config --list
6.2 Final recommended configuration
Here is a summary of the recommended configuration:
# Identité
git config --global user.name "Votre Nom"
git config --global user.email "[email protected]"
# Éditeur
git config --global core.editor "code --wait"
# Branche par défaut
git config --global init.defaultBranch main
# Fins de ligne (Windows)
git config --global core.autocrlf true
# Couleurs
git config --global color.ui auto
# Alias utiles
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.lg "log --oneline --graph --all"
6.3 Resulting ~/.gitconfig file
[user]
name = Votre Nom
email = [email protected]
[core]
editor = code --wait
autocrlf = true
[init]
defaultBranch = main
[color]
ui = auto
[alias]
st = status
co = checkout
br = branch
ci = commit
lg = log --oneline --graph --all
Next step
Now that Git is configured, let's move on to the core Git workflow commands!