Skip to main content

Installation & Setup

Quick Summary

Git runs on every major operating system. Installation takes under 2 minutes, and first-time setup requires just two commands (user.name and user.email). After that, you're ready to initialize repositories and start tracking changes.


Install Git

sudo apt update
sudo apt install -y git

Verify Installation

git --version

Expected output (example):

git version 2.43.0
Minimum version

For full feature support (including partial clone, sparse checkout, and improved performance), use Git 2.30+. Most modern Linux distributions ship with 2.40+.


First-Time Configuration

Git needs your identity for commit authorship. This is required before you can make any commits:

# Set your name (shown in every commit)
git config --global user.name "Your Name"

# Set your email (must match your GitHub account for linking)
git config --global user.email "your.email@example.com"
# Set default branch name to 'main' (instead of 'master')
git config --global init.defaultBranch main

# Set default editor (for commit messages, rebase, etc.)
git config --global core.editor "nano" # or: vim, code --wait

# Enable colored output
git config --global color.ui auto

# Set pull strategy to rebase (cleaner history)
git config --global pull.rebase true

# Set push default to current branch
git config --global push.default current

# Handle line endings (Linux/macOS)
git config --global core.autocrlf input

# Handle line endings (Windows)
# git config --global core.autocrlf true

Verify Your Configuration

git config --global --list

Expected output (example):

user.name=donnyaw
user.email=donnyaw@gmail.com
init.defaultbranch=main
core.editor=nano
color.ui=auto
pull.rebase=true
push.default=current
core.autocrlf=input

Configuration Levels

Git has three configuration levels, each overriding the previous:

LevelFlagFile LocationScope
System--system/etc/gitconfigAll users on the machine
Global--global~/.gitconfigYour user account
Local--local.git/config (inside repo)This repository only
# View all configs with their origin
git config --list --show-origin
Per-repo overrides

If you use different emails for work vs personal projects, set the email at the local level inside each repository:

cd ~/work/project
git config user.email "your.name@company.com"

Create Your First Repository

# Create a project directory
mkdir my-first-repo
cd my-first-repo

# Initialize Git
git init

Expected output:

Initialized empty Git repository in /home/user/my-first-repo/.git/

Make Your First Commit

# Create a file
echo "# My First Project" > README.md

# Stage the file
git add README.md

# Commit
git commit -m "Initial commit"

Expected output:

[main (root-commit) a1b2c3d] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 README.md

Essential .gitignore

Create a .gitignore file to exclude files that shouldn't be tracked:

# .gitignore

# OS files
.DS_Store
Thumbs.db

# IDE / editor files
.vscode/
.idea/
*.swp
*.swo

# Dependencies
node_modules/
vendor/
__pycache__/
*.pyc

# Environment files
.env
.env.local
.env.*.local

# Build output
dist/
build/
*.o
*.exe

# Logs
*.log
npm-debug.log*

# Secrets
*.pem
*.key
id_rsa
Global gitignore

For OS-specific files you always want ignored:

git config --global core.excludesFile ~/.gitignore_global
echo ".DS_Store" >> ~/.gitignore_global
echo "Thumbs.db" >> ~/.gitignore_global
echo "*.swp" >> ~/.gitignore_global

Troubleshooting

ProblemLikely CauseFix
git: command not foundGit not installed or not in PATHInstall Git, restart terminal
Author identity unknownuser.name / user.email not setRun git config --global user.name "..."
fatal: not a git repositoryNot inside a Git repoRun git init or cd to a repo
Wrong default branch nameOld Git version uses masterSet git config --global init.defaultBranch main

Best Practices

  • Set your identity immediately after installing Git
  • Use global config for defaults, local config for per-repo overrides
  • Always create a .gitignore before your first commit
  • Use main as your default branch name (modern convention)
  • Configure your preferred editor for commit messages

What's Next

  1. SSH Setup — Set up SSH keys for secure GitHub authentication
  2. Git Configuration (Deep Dive) — Advanced configuration, aliases, and optimization