Git Methods: Setup And Configuration

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 --versionshould 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:
System (all users): usually
/etc/gitconfigGlobal (your user):
~/.gitconfig(Windows:C:\Users\<you>\.gitconfig)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) inuser.email.
3) Quality-of-life defaults (recommended)
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
/wordthen Enter, pressnfor next match,qto quit.
9) Mini practice checklist
Print your effective config with file origins.
git config --list --show-originSet global name/email, then verify with
--get.Configure
init.defaultBranchandfetch.prune.Create a repo, override
user.emaillocally, and confirm precedence.Create an alias
lgand trygit lg.Open help for
configand skim the “FILES” and “EXAMPLES” sections:git help configList 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
.