Configure Your Git Environment
Time to set up your Git configuration. Follow these steps to establish your identity and preferences.
Exercise 1: Set Your Identity
Configure your name and email. Use the email associated with your GitHub account.
bash1$ git config --global user.name "Your Name"2$ git config --global user.email "your.email@example.com"
Verify It Worked
bash1$ git config --global user.name2Your Name34$ git config --global user.email5your.email@example.com
Exercise 2: Set Default Branch
Ensure new repositories use main as the default branch:
bash1$ git config --global init.defaultBranch main
Verify
bash1$ git config --global init.defaultBranch2main
Exercise 3: Enable Commit Signing (Optional)
If you have GPG set up, enable commit signing:
bash1$ git config --global commit.gpgsign true
Skip this step if you haven't configured GPG keys. You can enable it later.
Exercise 4: Configure Your Pager
Choose one of these options:
Option A: Using delta (if installed)
bash1$ git config --global core.pager "delta"
Option B: Basic less with good defaults
bash1$ git config --global core.pager "less -FX"
Test Your Pager
Create a test file and view a diff:
bash1$ mkdir /tmp/git-test && cd /tmp/git-test2$ git init3$ echo "line 1" > test.txt4$ git add test.txt5$ git commit -m "initial"6$ echo "line 2" >> test.txt7$ git diff
You should see a nicely formatted diff. Press q to exit.
Exercise 5: Enable Safety Nets
Enable rerere for conflict memory:
bash1$ git config --global rerere.enabled true
Add the status shortcut:
bash1$ git config --global alias.st "status -sb"
Test the Alias
bash1$ git st2## main3 M test.txt
Exercise 6: Full Verification
View all your global settings:
bash1$ git config --global --list
You should see output similar to:
1user.name=Your Name2user.email=your.email@example.com3init.defaultBranch=main4core.pager=delta5rerere.enabled=true6alias.st=status -sb
Cleanup
Remove the test directory:
bash1$ cd ~2$ rm -rf /tmp/git-test
Checklist
Before moving on, verify:
-
git config --global user.nameshows your name -
git config --global user.emailshows your GitHub email -
git config --global init.defaultBranchshowsmain -
git config --global core.pagershows your pager -
git config --global rerere.enabledshowstrue -
git stworks as an alias forstatus -sb
Troubleshooting
Config not saving?
Make sure you're using --global:
bash1# Wrong (saves to current repo only)2$ git config user.name "Name"34# Right (saves globally)5$ git config --global user.name "Name"
Wrong email linked to commits?
Check your GitHub profile settings. The email in your Git config must be listed in GitHub → Settings → Emails.
Pager showing weird characters?
Your terminal may not support the pager's features. Try:
bash1$ git config --global core.pager "less -FRX"
Key Takeaway
You've configured Git with your identity and preferences. These settings apply to every repository on your machine. You only need to do this once per machine.