Before you write your first commit, you need Git installed and configured correctly. This lesson walks through installation, identity configuration, SSH key setup, and your first connection to GitHub.
Installing Git
| OS | Method |
|---|---|
| macOS | brew install git (Homebrew) or install Xcode Command Line Tools: xcode-select --install |
| Ubuntu / Debian | sudo apt update && sudo apt install git |
| Fedora / RHEL | sudo dnf install git |
| Windows | Download Git for Windows from git-scm.com — includes Git Bash |
Verify installation:
git --version
# git version 2.44.0
Configuring Your Identity
Every Git commit records the author name and email. Set these once globally:
git config --global user.name "Ada Lovelace"
git config --global user.email "ada@example.com"
Other useful global settings:
# Set VS Code as your default editor (for commit messages)
git config --global core.editor "code --wait"
# Set the default branch name to 'main'
git config --global init.defaultBranch main
# Enable coloured output
git config --global color.ui auto
View all your current config:
git config --list --global
SSH Key Authentication
GitHub recommends SSH over HTTPS for authentication. With SSH, you generate a key pair on your machine: a private key (stays on your machine, never shared) and a public key (added to GitHub). When you push, GitHub verifies your identity using the key pair without a password.
Generate an SSH key
ssh-keygen -t ed25519 -C "ada@example.com"
# Accept the default file location (~/.ssh/id_ed25519)
# Optionally add a passphrase for extra security
Add the public key to GitHub
# Print your public key
cat ~/.ssh/id_ed25519.pub
Copy the output, then go to GitHub → Settings → SSH and GPG keys → New SSH key. Paste the key and give it a descriptive title (e.g., "Work laptop").
Test the connection
ssh -T git@github.com
# Hi ada! You have successfully authenticated...
Your First Repository
There are two ways to start working with a Git repository:
Option 1 — Initialize a new repository
mkdir my-project
cd my-project
git init
This creates a hidden .git directory — the repository database. Your project is now tracked by Git.
Option 2 — Clone an existing repository
git clone git@github.com:username/repository.git
This downloads the full repository (all commits, all branches) to a local directory.
The .gitignore File
A .gitignore file tells Git to never track matching files. Create one in your repository root:
# Dependencies
node_modules/
vendor/
# Build outputs
dist/
build/
*.o
*.pyc
# Environment and secrets
.env
.env.local
*.pem
*.key
# OS files
.DS_Store
Thumbs.db
# Editor files
.idea/
.vscode/
Never commit secrets (API keys, passwords, certificates) to a repository. Even if you delete them in a later commit, they remain in the Git history and can be recovered. If you accidentally commit a secret, rotate it immediately — the history should be considered compromised.
GitHub provides gitignore templates for every language and framework — a great starting point.