iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Install & Configure

Installing git on macOS, Linux, and Windows; verifying the version; setting your name + email + default branch.

Git — install + first config

EXAMPLE
# ===== Install =====
# macOS (via Xcode CLT or Homebrew):
xcode-select --install
# or:
brew install git

# Ubuntu / Debian:
sudo apt update && sudo apt install -y git

# Fedora / RHEL:
sudo dnf install -y git

# Arch:
sudo pacman -S git

# Windows:
winget install Git.Git
# or download from https://git-scm.com (includes Git Bash)

# ===== Verify =====
git --version
# git version 2.45.x or newer

# ===== First-run config =====
git config --global user.name  'Alex Chen'
git config --global user.email 'alex@example.com'
git config --global init.defaultBranch main
git config --global pull.rebase false       # 'merge' style; switch to 'true' if you prefer rebase
git config --global core.autocrlf input     # macOS/Linux; on Windows use 'true'

# Editor preference:
git config --global core.editor 'code --wait'    # VS Code as the commit editor

# Useful default aliases:
git config --global alias.s 'status -sb'
git config --global alias.l 'log --oneline --graph --decorate -20'
git config --global alias.co 'checkout'
git config --global alias.br 'branch'

# ===== SSH key for GitHub / GitLab =====
ssh-keygen -t ed25519 -C 'alex@example.com'
# Press enter for default path; set a passphrase
cat ~/.ssh/id_ed25519.pub
# Paste into GitHub -> Settings -> SSH and GPG keys

# Test:
ssh -T git@github.com

# ===== Smoke test =====
mkdir hello-git && cd hello-git
git init
echo 'hello' > README.md
git add README.md
git commit -m 'initial commit'
git log --oneline

# ===== Verify everything =====
git config --get user.name
git config --get user.email
git config --get init.defaultBranch
git config --list --global

# ===== Patterns to internalise =====
# - Set user.name + user.email globally; per-repo overrides only when needed
# - SSH keys per machine; never share private keys
# - Aliases (s, l) save real time once the muscle memory kicks in
# - Use a credential helper for HTTPS (avoids retyping passwords)

# ===== Pitfalls =====
# - Using your work email on personal projects (commits inherit author)
# - core.autocrlf wrong for your platform -> noisy diffs
# - Forgetting to register the SSH key with the host -> 'Permission denied (publickey)'
# - Mixing global identity across employer + personal accounts (use directory-scoped includeIf)

Why it matters

Install git, set name + email + default branch, add an SSH key, and you are ready for any repo. The little aliases and the credential helper pay for themselves in the first week. Skip them and you keep retyping the same flags forever.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
# macOS:    brew install git
# Ubuntu:   apt install git
# Windows:  https://git-scm.com
git --version
Try it Yourself »

Discussion

Loading…