Install & Configure
Set up Git on your machine for the first time
Skills taught: git.install, git.config
Installing Git
# macOS (via Homebrew)
brew install git
# Ubuntu / Debian
sudo apt update && sudo apt install git
# Windows
# Download from https://git-scm.com/download/win
# Or via winget:
winget install --id Git.Git
# Verify installation
git --version
# → git version 2.45.0
First-time configuration
These two commands are the only required setup. Run them once on each machine you use Git on.
# Set your identity — embedded in every commit
git config --global user.name "Prashant Kumar"
git config --global user.email "prashant@example.com"
# Set default branch name to 'main' (modern standard)
git config --global init.defaultBranch main
# Set your preferred editor for commit messages
git config --global core.editor "code --wait" # VS Code
# git config --global core.editor "nano" # Nano (simpler)
# git config --global core.editor "vim" # Vim
# Verify all settings
git config --list
Useful optional settings
# Colorised output (usually on by default)
git config --global color.ui auto
# Better diff output
git config --global diff.algorithm histogram
# Rebase instead of merge when pulling (cleaner history)
git config --global pull.rebase true
# Show shortcuts — list all aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.lg "log --oneline --graph --all"
# Where global config is stored
cat ~/.gitconfig
Tip: Use git config --list --show-origin to see every setting and which file it came from. Helpful for debugging unexpected behaviour.
Frequently Asked Questions
Can I use different emails for work and personal projects?
Yes. Set your global config to your personal email. In each work repo, run git config --local user.email 'you@company.com' to override it for that repo only. Git's [includeIf] in .gitconfig can automate this by directory.
What editor should I choose?
VS Code (code --wait) is the most user-friendly. Nano is simple and terminal-based. Vim is powerful but has a steep learning curve. If you skip this setting, Git uses the system default (often vi on macOS/Linux).