Skip to main content

Command Palette

Search for a command to run...

Git Methods: Setup And Configuration

Published
4 min read
Git Methods: Setup And Configuration
M

Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).

This hands-on tutorial shows how to (1) configure Git at different scopes with git config, and (2) use git help effectively.

0) Prerequisites

  • Git installed (git --version should print a version).

  • A terminal (PowerShell, CMD, Git Bash, Terminal, etc.).

1) Understand config scopes (system → global → local)

Git reads settings from multiple places. Later scopes override earlier ones:

  1. System (all users): usually /etc/gitconfig

  2. Global (your user): ~/.gitconfig (Windows: C:\Users\<you>\.gitconfig)

  3. Local (per repo): <repo>/.git/config

Inspect everything (with file origins):

git config --list --show-origin

2) Set your identity (global)

Set once for all your repositories (you can override per-repo later).

git config --global user.name  "Your Name"
git config --global user.email "you@example.com"

Verify:

git config --global --get user.name
git config --global --get user.email

Tip (GitHub): if you want to hide your real email, use GitHub’s noreply email (e.g., 123456+username@users.noreply.github.com) in user.email.

3.1 Default branch name

git config --global init.defaultBranch main

3.2 Line endings (pick one appropriate to your OS/team)

  • Windows developers collaborating cross-platform:
git config --global core.autocrlf true
  • macOS/Linux or cross-platform teams using LF in repos:
git config --global core.autocrlf input

3.3 Friendly visuals and pager

git config --global color.ui auto
git config --global core.pager "less -+F -X"   # smoother paging

3.4 Safer pulls and cleaner fetches

git config --global pull.rebase false   # or true if you prefer linear history
git config --global rebase.autoStash true
git config --global fetch.prune true

3.5 Smarter diffs

git config --global diff.renames true

3.6 Useful aliases (optional but handy)

git config --global alias.st "status -sb"
git config --global alias.lg "log --graph --oneline --decorate --all"
git config --global alias.co "checkout"
git config --global alias.br "branch"
git config --global alias.ci "commit"

Check results:

git config --global --list

4) Per-repository overrides (local)

Create a test repo and override a setting locally:

mkdir git-config-demo && cd git-config-demo
git init
git config user.email "project-specific-email@example.com"   # local scope

Confirm precedence (local wins):

git config --show-origin --get user.email
git config --get user.email

You should see the value coming from .git/config in this repo.

5) View, edit, change, and remove settings

5.1 Read values

git config --get user.name
git config --global --get core.autocrlf
git config --system --get color.ui

5.2 Edit the whole file (opens your editor)

git config --global --edit
git config --edit                # edits local .git/config

5.3 Replace or add values

git config --global --replace-all alias.co "switch -c"

5.4 Unset values

git config --global --unset alias.co
git config --global --unset-all alias.co   # if multiple values

6) Credentials & signing (optional but common)

6.1 Credential helper

  • Windows (Git Credential Manager):
git config --global credential.helper manager-core
  • macOS (Keychain):
git config --global credential.helper osxkeychain
  • Plaintext store (avoid on shared machines):
git config --global credential.helper store

6.2 Sign commits (GPG or SSH—example uses GPG)

git config --global user.signingkey YOUR_GPG_KEY_ID
git config --global commit.gpgSign true

7) Troubleshooting configuration

  • See where a value comes from:
git config --show-origin --get core.autocrlf
  • Dump effective config for the current repo:
git config --list --show-origin
  • Validate an alias works:
git lg

8) Using git help like a pro

Three equivalent ways to open a command’s help:

git help <command>
git <command> --help
man git-<command>            # if man pages are installed

Examples:

git help config
git help log
git help rebase

List all commands:

git help -a

Open in your browser (if supported):

git help --web config

Guides & concepts (not just command refs):

git help -g

Search inside a help page:

  • In less/man: type /word then Enter, press n for next match, q to quit.

9) Mini practice checklist

  1. Print your effective config with file origins.

     git config --list --show-origin
    
  2. Set global name/email, then verify with --get.

  3. Configure init.defaultBranch and fetch.prune.

  4. Create a repo, override user.email locally, and confirm precedence.

  5. Create an alias lg and try git lg.

  6. Open help for config and skim the “FILES” and “EXAMPLES” sections:

     git help config
    
  7. List all commands:

     git help -a
    

10) Quick reference (copy/paste)

# Identity (global)
git config --global user.name  "Your Name"
git config --global user.email "you@example.com"

# Defaults
git config --global init.defaultBranch main
git config --global fetch.prune true
git config --global pull.rebase false
git config --global rebase.autoStash true
git config --global color.ui auto

# Line endings (choose one)
git config --global core.autocrlf true   # Windows
# or
git config --global core.autocrlf input  # macOS/Linux

# Aliases
git config --global alias.st "status -sb"
git config --global alias.lg "log --graph --oneline --decorate --all"

# Inspect & edit
git config --list --show-origin
git config --global --edit
git help -a
git help config

.

3 views