إنتقل إلى المحتوى الرئيسي

Git Initial Configuration

Module 00 30 min

Section Objectives

  • Configure your Git identity (name and email)
  • Set your preferred editor
  • Understand the 3 levels of Git configuration
  • Create useful aliases
  • Set up SSH key authentication for GitHub

The 3 Configuration Levels

Git has 3 levels of configuration, from most specific to most general:

LevelScopeFile LocationOption
SystemAll users on the machine/etc/gitconfig--system
GlobalCurrent user, all repos~/.gitconfig--global
LocalCurrent repository only.git/config--local

A more specific level overrides a more general level.


Essential Configuration

1. Your Identity

This is the most important configuration — every commit will use this information:

git config --global user.name "Your Full Name"
git config --global user.email "your.email@example.com"
Use your real email

Use the same email as your GitHub account. GitHub uses this email to attribute commits to your profile. If the emails don't match, your commits won't appear on your contribution graph.

2. Default Editor

Git opens an editor for commit messages. Configure VS Code:

# VS Code (recommended)
git config --global core.editor "code --wait"

# Vim (default on many systems)
git config --global core.editor "vim"

# Nano (simpler than Vim)
git config --global core.editor "nano"

# Notepad++ (Windows)
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"

3. Default Branch Name

GitHub now uses main as the default branch name (previously master):

git config --global init.defaultBranch main

4. Line Endings

Important to avoid issues between Windows and macOS/Linux:

# Windows
git config --global core.autocrlf true

# macOS / Linux
git config --global core.autocrlf input

5. Default Pull Strategy

# Recommended: rebase on pull (cleaner history)
git config --global pull.rebase true

# Alternative: merge on pull (traditional)
# git config --global pull.rebase false

Useful Aliases

Aliases let you create shortcuts for frequently used commands:

# Short status
git config --global alias.st status

# Compact log with graph
git config --global alias.lg "log --oneline --graph --decorate --all"

# Short log
git config --global alias.ll "log --oneline -10"

# List branches
git config --global alias.br "branch -a"

# Quick commit (stage all + commit)
git config --global alias.cam "commit -am"

# Undo last commit (keep changes)
git config --global alias.undo "reset HEAD~1 --mixed"

# Show what will be pushed
git config --global alias.outgoing "log @{u}.. --oneline"

Usage after creating alias:

git lg        # instead of: git log --oneline --graph --decorate --all
git st # instead of: git status
git ll # shows last 10 commits

Viewing Your Configuration

# Show all active config (merged levels)
git config --list

# Show only global config
git config --global --list

# Show a specific value
git config user.name
git config user.email

# Edit global config file directly
git config --global --edit

Sample .gitconfig File

[user]
name = Alice Dupont
email = alice@example.com

[core]
editor = code --wait
autocrlf = input # or true on Windows

[init]
defaultBranch = main

[pull]
rebase = true

[alias]
st = status
lg = log --oneline --graph --decorate --all
ll = log --oneline -10
br = branch -a
cam = commit -am
undo = reset HEAD~1 --mixed

[color]
ui = auto

SSH Authentication Setup

Using SSH is more secure and convenient than a password for GitHub (no repeated authentication prompts):

Generate an SSH Key

# Generate an Ed25519 key (recommended, modern and secure)
ssh-keygen -t ed25519 -C "your.email@example.com"

# If your system doesn't support Ed25519, use RSA:
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

When prompted:

  • File location: Press Enter for default (~/.ssh/id_ed25519)
  • Passphrase: Choose a strong passphrase (recommended) or leave empty

Add the SSH Key to the Agent

# Start the SSH agent
eval "$(ssh-agent -s)"

# Add your key
ssh-add ~/.ssh/id_ed25519

Add the Public Key to GitHub

# Display your public key to copy it
cat ~/.ssh/id_ed25519.pub

Then on GitHub:

  1. Go to SettingsSSH and GPG keys
  2. Click New SSH key
  3. Give it a descriptive name (e.g., "My laptop 2026")
  4. Paste the key content
  5. Click Add SSH key

Test the SSH Connection

ssh -T git@github.com
# Expected: Hi username! You've successfully authenticated...

Configure GPG Signing (Optional)

For maximum security, you can sign your commits with a GPG key. This proves that commits really come from you:

# Generate a GPG key
gpg --full-generate-key
# Choose: RSA and RSA, 4096 bits, no expiration

# List your keys to get the key ID
gpg --list-secret-keys --keyid-format=long

# Configure Git to use your key
git config --global user.signingkey YOUR_KEY_ID
git config --global commit.gpgsign true

Summary Checklist

  • user.name configured
  • user.email configured (same as GitHub)
  • Default editor configured
  • init.defaultBranch = main
  • core.autocrlf configured for your OS
  • Useful aliases added
  • SSH key generated and added to GitHub
  • SSH connection tested (ssh -T git@github.com)

Next Steps