Installation & Setup
Install Git on your machine, configure your identity, and verify everything works before writing a single command.
Introduction
Before you can use Git you need to install it and tell it who you are. Every commit you make will be stamped with your name and email — this is how collaborators know who made which change. Setup takes about 5 minutes and you only do it once.
Installing Git
Windows
Download the installer from git-scm.com/download/win and run it. The defaults are fine for most options. The installer includes Git Bash — a Unix-style terminal that works much better for Git than the default Windows Command Prompt.
git from any terminal including VS Code's integrated terminal.macOS
The easiest way is via Homebrew. If you have Homebrew installed, run:
brew install git
Alternatively, just type git in the Terminal — macOS will prompt you to install the Xcode Command Line Tools, which includes Git.
Linux (Ubuntu/Debian)
sudo apt update
sudo apt install git
Verify installation
Open a terminal and run:
git --version
# Expected output: git version 2.x.x
If you see a version number, Git is installed correctly.
First-Time Configuration
Git needs to know your name and email to label your commits. Run these two commands — replace with your own details:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
--global means these settings apply to every repository on your computer. You can override them per-project by running the same commands without --global inside that project's folder.
Set your default editor
When Git needs you to write a longer commit message, it opens a text editor. VS Code is a great choice:
git config --global core.editor "code --wait"
The --wait flag tells Git to wait until you close the VS Code tab before continuing.
Set the default branch name
Modern convention is to call the main branch main (not master). Configure this globally:
git config --global init.defaultBranch main
View your configuration
git config --list
# Shows all your current settings
git config user.name
# Shows just your name
Where Configuration is Stored
Git stores global configuration in a plain text file in your home directory:
- Windows:
C:\Users\YourName\.gitconfig - macOS / Linux:
~/.gitconfig
You can edit this file directly if you prefer. Here is what it looks like:
[user]
name = Your Name
email = you@example.com
[core]
editor = code --wait
[init]
defaultBranch = main
Setting Up SSH Keys (Optional but Recommended)
When you push code to GitHub, you need to authenticate. The modern, secure approach is SSH keys — you generate a key pair and add the public key to your GitHub account. This lets you push code without typing a password every time.
Generate an SSH key
# Replace with your GitHub email
ssh-keygen -t ed25519 -C "you@example.com"
# Press Enter to accept the default file location
# Enter a passphrase (optional but recommended)
# Press Enter again to confirm
Copy the public key
# macOS
cat ~/.ssh/id_ed25519.pub | pbcopy
# Windows (Git Bash)
cat ~/.ssh/id_ed25519.pub | clip
# Linux
cat ~/.ssh/id_ed25519.pub
Then go to GitHub → Settings → SSH and GPG keys → New SSH key and paste the copied key.
Test the connection
ssh -T git@github.com
# Expected: Hi username! You've successfully authenticated...
Common Mistakes
- Using a different email than your GitHub account. GitHub uses your email to link commits to your profile. Use the same email for both.
- Skipping the
--globalflag. Without it, the configuration only applies to the current repository. - Not setting the default branch name. This prevents the inconsistency of some repos using
masterand others usingmain. - Using HTTPS instead of SSH for GitHub. HTTPS requires a Personal Access Token as of 2021 (GitHub removed password authentication). SSH is simpler once set up.
Practice Exercise
- Install Git if you haven't already and verify with
git --version. - Run
git config --global user.name "Your Name"andgit config --global user.email "you@example.com"with your real details. - Run
git config --listand confirm you can see your name and email. - Run
git config --global init.defaultBranch main. - (Optional) Generate an SSH key and add it to GitHub if you have an account.
Assignment
Find the .gitconfig file on your computer (see paths above). Open it in a text editor and write down what sections and keys it contains. Add this optional but useful setting:
git config --global color.ui auto
This enables coloured terminal output for Git commands — green for added lines, red for removed lines.
Interview Questions
- What does
git config --globaldo? — Sets a configuration value that applies to all repositories on the current user's account, stored in~/.gitconfig. - Why do we set a name and email in Git? — Every commit is permanently stamped with this information so collaborators can see who made each change.
- What is the difference between HTTPS and SSH for GitHub? — HTTPS uses a Personal Access Token for authentication; SSH uses a key pair. SSH is more convenient for daily use once configured.