10 minworkshop

Configure Your Git Environment

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.

bash
1$ git config --global user.name "Your Name"
2$ git config --global user.email "your.email@example.com"

Verify It Worked

bash
1$ git config --global user.name
2Your Name
3
4$ git config --global user.email
5your.email@example.com

Exercise 2: Set Default Branch

Ensure new repositories use main as the default branch:

bash
1$ git config --global init.defaultBranch main

Verify

bash
1$ git config --global init.defaultBranch
2main

Exercise 3: Enable Commit Signing (Optional)

If you have GPG set up, enable commit signing:

bash
1$ 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)

bash
1$ git config --global core.pager "delta"

Option B: Basic less with good defaults

bash
1$ git config --global core.pager "less -FX"

Test Your Pager

Create a test file and view a diff:

bash
1$ mkdir /tmp/git-test && cd /tmp/git-test
2$ git init
3$ echo "line 1" > test.txt
4$ git add test.txt
5$ git commit -m "initial"
6$ echo "line 2" >> test.txt
7$ git diff

You should see a nicely formatted diff. Press q to exit.

Exercise 5: Enable Safety Nets

Enable rerere for conflict memory:

bash
1$ git config --global rerere.enabled true

Add the status shortcut:

bash
1$ git config --global alias.st "status -sb"

Test the Alias

bash
1$ git st
2## main
3 M test.txt

Exercise 6: Full Verification

View all your global settings:

bash
1$ git config --global --list

You should see output similar to:

1user.name=Your Name
2user.email=your.email@example.com
3init.defaultBranch=main
4core.pager=delta
5rerere.enabled=true
6alias.st=status -sb

Cleanup

Remove the test directory:

bash
1$ cd ~
2$ rm -rf /tmp/git-test

Checklist

Before moving on, verify:

  • git config --global user.name shows your name
  • git config --global user.email shows your GitHub email
  • git config --global init.defaultBranch shows main
  • git config --global core.pager shows your pager
  • git config --global rerere.enabled shows true
  • git st works as an alias for status -sb

Troubleshooting

Config not saving?

Make sure you're using --global:

bash
1# Wrong (saves to current repo only)
2$ git config user.name "Name"
3
4# 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:

bash
1$ 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.