| |

Git 1c 🧩 Initial Git Configuration

Git works out of the box, but it needs a few settings before you can commit anything meaningful. The most important are your name and email — Git embeds them in every commit as the author. Beyond that, a handful of config options — editor, aliases, default branch — make daily work faster and less error-prone.

This chapter walks through the essential configuration you should run once after installing Git. Set these now, and you’ll never hit “please tell me who you are” again.


1. Set your user name

git config --global user.name "Your Name"

Replace "Your Name" with the name you want to appear in your commits — usually your real name or your handle. This is what shows up in git log, on GitHub, and in every commit you push.

The --global flag writes the setting to ~/.gitconfig so it applies to every repository on your machine. Without it, the setting would apply only to the current repository.

Why this matters: Git rejects any commit without an author. If user.name is unset, git commit fails with a message telling you to configure it. Set it once and forget it.


2. Set your email address

git config --global user.email "your.email@example.com"

Replace "your.email@example.com" with the email you want tied to your commits. On GitHub, GitLab, and Bitbucket, this is often how the platform links your local commits to your account — so using the same email you registered with means your commits show up on your profile.

If you want to hide your real email, GitHub and GitLab both provide a noreply address in your account settings. Use that instead, and the platform will still attribute the commit to you.

Why this matters: Along with user.name, the email is mandatory. It also determines whether a commit appears as “verified” or linked to your account.


3. Configure your text editor

Git needs an editor for commit messages, merge messages, and interactive rebases. Without configuring one, it opens the system default — usually Vim — which surprises people who don’t use Vim.

Set your preferred editor:

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

# Sublime Text
git config --global core.editor "subl -n -w"

# Vim
git config --global core.editor "vim"

# Nano
git config --global core.editor "nano"

The --wait flag for VS Code (and -w for Sublime) tells the editor to block Git until you close the file. Without it, Git thinks you’re done editing and commits an empty message.

Why this matters: Every commit that needs a message — merge commits, git commit --amend, git rebase -i — opens your editor. Configure it once, and Git behaves the way you expect.


4. Configure aliases

Aliases are shortcuts for longer Git commands. They save keystrokes and reduce typos.

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status

After setting these, git co works like git checkout, git br like git branch, and so on.

More useful aliases:

# Short status
git config --global alias.s "status -s"

# Pretty log one-liner
git config --global alias.lg "log --oneline --graph --decorate"

# Last commit
git config --global alias.last "log -1 HEAD"

# Undo last commit, keep changes staged
git config --global alias.unstage "reset HEAD --"

The lg alias is a common favorite — a compact visual history with branches and tags.

Why this matters: Git commands are verbose. Aliases cut down on typing, and if you keep them consistent across machines, they become muscle memory.


5. Enable auto-correct

Git can catch typos in commands and suggest the right one.

git config --global help.autocorrect 1

With 1 set, Git waits 1 tenth of a second before running the corrected command. You’ll see WARNING: You called a Git command named 'stauts', which does not exist. Continuing under the assumption that you meant 'status' in 0.1 seconds....

To require confirmation:

git config --global help.autocorrect prompt

Useful for fat-fingered days. Some people find it annoying; others swear by it.

Why this matters: Typos on checkout, commit, rebase are common. Auto-correct catches them before you type them again.


6. Set the default branch name

Historically, git init created a branch named master. Since Git 2.28, you can change that default.

git config --global init.defaultBranch main

Or use any name you prefer:

git config --global init.defaultBranch development

main is now the convention on GitHub, GitLab, and most modern projects. Setting it here means every new repository starts with main — no need to rename master each time.

Why this matters: Naming consistency across your projects avoids “is the default branch master or main?” confusion. Set it once, and every new repo matches the modern standard.


7. Configure an SSH key

SSH keys let you authenticate with GitHub, GitLab, or Bitbucket without typing a password for every push or pull. They’re not strictly required if you use HTTPS, but they’re the smoother option for regular work.

Generate a key:

ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

Follow the prompts. When asked where to save the key, press Enter to accept the default (~/.ssh/id_rsa). When asked for a passphrase, either type one (more secure) or press Enter for none.

Newer GitHub setups use Ed25519 instead of RSA — smaller and faster:

ssh-keygen -t ed25519 -C "your.email@example.com"

Add the key to the SSH agent:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

The agent holds the key in memory, so you don’t re-type the passphrase on every operation.

Add the public key to your account:

cat ~/.ssh/id_rsa.pub

Copy the entire output, then paste it into your GitHub/GitLab/Bitbucket SSH keys settings.

Why this matters: SSH keys are the standard for developer workflows. Set up once, and you’ll never be prompted for a password.


8. Verify your configuration

After configuring, list all global settings:

git config --global --list

You should see entries for user.name, user.email, init.defaultbranch, core.editor, and each alias you added.

For a single value:

git config --global user.name

For a full view with the config file path:

git config --global --list --show-origin

This shows where each setting comes from — handy when debugging why a value isn’t what you expected.

You are now ready to use Git. Every commit will carry your name and email, your editor will open for commit messages, aliases will shorten common commands, and new repositories will start on main.


Complete Example Session

# ============================================
# PART 1: USER NAME
# ============================================

git config --global user.name "Kronos"

# ============================================
# PART 2: EMAIL
# ============================================

git config --global user.email "kronos@example.com"

# ============================================
# PART 3: EDITOR
# ============================================

git config --global core.editor "nano"

# ============================================
# PART 4: ALIASES
# ============================================

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.lg "log --oneline --graph --decorate"

# ============================================
# PART 5: AUTO-CORRECT
# ============================================

git config --global help.autocorrect 1

# ============================================
# PART 6: DEFAULT BRANCH
# ============================================

git config --global init.defaultBranch main

# ============================================
# PART 7: SSH KEY
# ============================================

ssh-keygen -t ed25519 -C "kronos@example.com"
# [ Generating public/private ed25519 key pair. ]
# [ Enter file in which to save the key (/home/kronos/.ssh/id_ed25519): ]
# [ Enter passphrase (empty for no passphrase): ]
# [ Enter same passphrase again: ]
# [ Your identification has been saved in /home/kronos/.ssh/id_ed25519 ]
# [ Your public key has been saved in /home/kronos/.ssh/id_ed25519.pub ]

eval "$(ssh-agent -s)"
# [ Agent pid 12345 ]

ssh-add ~/.ssh/id_ed25519
# [ Identity added: /home/kronos/.ssh/id_ed25519 ]

cat ~/.ssh/id_ed25519.pub
# [ ssh-ed25519 AAAAC3... kronos@example.com ]
# (copy this into GitHub/GitLab)

# ============================================
# PART 8: VERIFY ALL SETTINGS
# ============================================

git config --global --list
# [ user.name=Kronos ]
# [ user.email=kronos@example.com ]
# [ core.editor=nano ]
# [ alias.co=checkout ]
# [ alias.br=branch ]
# [ alias.ci=commit ]
# [ alias.st=status ]
# [ alias.lg=log --oneline --graph --decorate ]
# [ help.autocorrect=1 ]
# [ init.defaultbranch=main ]

# ============================================
# PART 9: VERIFY ONE SETTING
# ============================================

git config --global user.name
# [ Kronos ]

# ============================================
# PART 10: SHOW ORIGIN
# ============================================

git config --global --list --show-origin
# [ file:/home/kronos/.gitconfig  user.name=Kronos ]
# [ file:/home/kronos/.gitconfig  user.email=kronos@example.com ]
# [ ... ]

# ============================================
# PART 11: CONFIG FILE
# ============================================

cat ~/.gitconfig
# [ [user] ]
# [     name = Kronos ]
# [     email = kronos@example.com ]
# [ [core] ]
# [     editor = nano ]
# [ [alias] ]
# [     co = checkout ]
# [     br = branch ]
# [     ci = commit ]
# [     st = status ]
# [     lg = log --oneline --graph --decorate ]
# [ [help] ]
# [     autocorrect = 1 ]
# [ [init] ]
# [     defaultBranch = main ]

Quick Reference

Essential Settings

SettingCommand
Namegit config --global user.name "Your Name"
Emailgit config --global user.email "you@example.com"
Editorgit config --global core.editor "nano"
Default branchgit config --global init.defaultBranch main
Auto-correctgit config --global help.autocorrect 1

Editor Commands

EditorCommand
VS Code"code --wait"
Sublime"subl -n -w"
Vim"vim"
Nano"nano"
Emacs"emacs"

Common Aliases

AliasExpands to
cocheckout
brbranch
cicommit
ststatus
sstatus -s
lglog --oneline --graph --decorate
lastlog -1 HEAD

SSH Key Setup

StepCommand
Generatessh-keygen -t ed25519 -C "email"
Start agenteval "$(ssh-agent -s)"
Add keyssh-add ~/.ssh/id_ed25519
Copy publiccat ~/.ssh/id_ed25519.pub

Verification

CommandPurpose
git config --global --listAll global settings
git config --global user.nameOne setting
git config --global --list --show-originWith file source
cat ~/.gitconfigRaw config file

Config Scope

FlagScopeFile
--systemAll users/etc/gitconfig
--globalYour user~/.gitconfig
--localCurrent repo.git/config

Precedence: local → global → system

Auto-Correct Values

ValueBehavior
0Disabled (default)
1Wait 0.1s, then run
NWait N tenths of a second
promptAsk before running
immediateRun instantly

Best Practices

✅ Do This:

# Set name and email immediately
git config --global user.name "Kronos"
git config --global user.email "kronos@example.com"  # ✅

# Use the same email as your GitHub account
git config --global user.email "you@github-email"    # ✅

# Configure your editor
git config --global core.editor "code --wait"        # ✅

# Set the modern default branch
git config --global init.defaultBranch main          # ✅

# Add a few high-value aliases
git config --global alias.lg "log --oneline --graph --decorate"  # ✅

# Use Ed25519 for new SSH keys
ssh-keygen -t ed25519 -C "email"                     # ✅

# Verify config
git config --global --list                           # ✅

❌ Don’t Do This:

# Don't skip name/email config
# Git will reject commits                           # ❌

# Don't use --local for global settings you want everywhere
git config user.name "Name"                          # ⚠️  repo-only

# Don't set an editor you don't have
git config --global core.editor "code --wait"        # ⚠️  only if installed

# Don't use RSA when Ed25519 is supported
ssh-keygen -t rsa -b 4096                            # ⚠️  Ed25519 is better

# Don't forget --wait with GUI editors
git config --global core.editor "code"               # ❌ editor returns early

# Don't paste the wrong SSH key
cat ~/.ssh/id_ed25519                                # ❌ never share private

# Don't commit with a work email on personal projects
git config --global user.email "work@company.com"    # ⚠️  per-repo override instead

Common Pitfalls

PitfallProblemSolution
Missing name/emailCommit failsConfigure both
Editor doesn’t blockEmpty commit messageAdd --wait
Wrong default branchNew repos start on masterSet init.defaultBranch
SSH key passphrase forgottenCan’t authenticateRegenerate or use SSH agent
Alias conflictsAlias shadows a real commandRename the alias
Local overrides globalConfusing valuesCheck --show-origin
Wrong email usedCommits not linked to accountSet correct email globally
Auto-correct too aggressiveRuns unexpected commandsUse prompt mode

Real-World Examples

1. Set name

git config --global user.name "Kronos"

The first thing to configure after install.

2. Set email

git config --global user.email "kronos@example.com"

Should match your Git platform account.

3. Configure VS Code

git config --global core.editor "code --wait"

The --wait flag is essential.

4. Set default branch

git config --global init.defaultBranch main

Modern convention.

5. Alias for status

git config --global alias.st status

git st becomes the short form.

6. Alias for pretty log

git config --global alias.lg "log --oneline --graph --decorate"

A one-line history with branches and tags.

7. Enable auto-correct

git config --global help.autocorrect 1

Typos get fixed automatically.

8. Generate SSH key

ssh-keygen -t ed25519 -C "kronos@example.com"

Press Enter to accept defaults.

9. Add key to agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Key stays in memory for the session.

10. View config with source

git config --global --list --show-origin

Shows where every value comes from.


Visual: What Gets Stored in a Commit

┌──────────────────────────────────────────────┐
│  Every commit contains:                      │
│                                              │
│  ┌────────────────────────────────────────┐  │
│  │ author:    Kronos <kronos@example.com> │  │
│  │ date:      2024-01-15 10:30:00         │  │
│  │ message:   Add login endpoint          │  │
│  │ tree hash: a1b2c3d4                    │  │
│  │ parent:    e5f6g7h8                    │  │
│  └────────────────────────────────────────┘  │
│                                              │
│  Name + email come from your git config      │
│                                              │
└──────────────────────────────────────────────┘

Visual: Config File Structure

┌──────────────────────────────────────────────┐
│  ~/.gitconfig                                │
│                                              │
│  [user]                                      │
│      name = Kronos                           │
│      email = kronos@example.com              │
│                                              │
│  [core]                                      │
│      editor = code --wait                    │
│                                              │
│  [alias]                                     │
│      co = checkout                           │
│      br = branch                             │
│      lg = log --oneline --graph --decorate   │
│                                              │
│  [init]                                      │
│      defaultBranch = main                    │
│                                              │
│  [help]                                      │
│      autocorrect = 1                         │
│                                              │
└──────────────────────────────────────────────┘

Visual: Config Precedence

┌──────────────────────────────────────────────┐
│  /etc/gitconfig       (--system)             │
│        │                                     │
│        ▼                                     │
│  ~/.gitconfig         (--global)             │
│        │                                     │
│        ▼                                     │
│  .git/config          (--local)              │
│                                              │
│  Local overrides global overrides system     │
│  Most specific wins                          │
│                                              │
└──────────────────────────────────────────────┘

Visual: SSH Authentication Flow

┌──────────────────────────────────────────────┐
│  Your machine                                │
│  ~/.ssh/id_ed25519       ← private key       │
│  ~/.ssh/id_ed25519.pub   ← public key        │
│                                              │
└─────────────────┬────────────────────────────┘
                  │
                  │  git push
                  ▼
┌──────────────────────────────────────────────┐
│  GitHub / GitLab                             │
│  Stores your public key                      │
│                                              │
│  Challenges your client                      │
│  Client decrypts with private key            │
│  Access granted ✅                           │
│                                              │
└──────────────────────────────────────────────┘

Summary

SettingPurposeCommand
user.nameCommit authorgit config --global user.name "Name"
user.emailCommit emailgit config --global user.email "e@x"
core.editorEditor for messagesgit config --global core.editor "nano"
alias.*Command shortcutsgit config --global alias.co checkout
help.autocorrectFix typosgit config --global help.autocorrect 1
init.defaultBranchDefault branchgit config --global init.defaultBranch main
SSH keyPasswordless authssh-keygen -t ed25519 -C "e@x"

Key takeaways:

  • Name and email are mandatory — Git refuses to commit without them
  • Use the same email as your GitHub/GitLab account so commits are linked to your profile
  • Configure a text editor — the --wait flag is essential for GUI editors
  • Aliases save keystrokes — co, br, st, lg are the common ones
  • Auto-correct catches typos — use 1 for silent fixing or prompt for confirmation
  • Set init.defaultBranch main — the modern convention
  • SSH keys enable passwordless auth — Ed25519 is the modern choice
  • --global applies to your user; --local overrides per repo
  • Verify everything with git config --global --list
  • Settings live in ~/.gitconfig — editable directly or via git config

Remember: Configuration happens once, but its effect lasts for every commit. Set your name and email, choose your editor, define the aliases you’ll use most, and set the default branch to main. Add an SSH key for smoother pushes. Then verify with git config --global --list and start working.


Stop using slow, ad-bloated tool sites! 🤮

🔎 Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)

⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free

🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!