Before you can start using Git to track your projects, you need to install it on your computer and configure it with your identity. This lesson will walk you through installing Git on Windows, macOS, and Linux, then show you how to configure the essential settings that identify you as the author of your commits. By the end, you'll have Git fully set up and ready to create your first repository!
Step 1: Check If Git Is Already Installed
Before installing Git, let's check if it's already on your system. Many computers, especially Macs and Linux machines, come with Git pre-installed.
Open Your Terminal/Command Prompt
First, you need to open a command-line interface:
- Windows: Search for "Command Prompt" or "PowerShell" in the Start menu
- Mac: Open "Terminal" from Applications → Utilities, or press
Cmd + Spaceand type "Terminal" - Linux: Press
Ctrl + Alt + Tor search for "Terminal" in your applications
Check the Git Version
In your terminal, type this command and press Enter:
git --versionYou'll see one of two results:
Git is installed: You'll see something like:
git version 2.43.0Great! You can skip to the configuration section. The exact version number doesn't matter much—any version 2.x is fine for learning.
Git is not installed: You'll see an error like:
'git' is not recognized as an internal or external commandNo problem! Continue to the installation section below for your operating system.
Installing Git on Windows
Windows doesn't include Git by default, but installation is straightforward.
Method 1: Official Git for Windows (Recommended)
- Download the installer: Go to git-scm.com/download/win and the download should start automatically
- Run the installer: Double-click the downloaded
.exefile - Follow the installation wizard: You'll see many options—here are the recommended settings:
Important Installation Options:
- Select Components: Keep default selections (Git Bash, Git GUI)
- Default editor: Choose your preferred text editor (VS Code is recommended if you have it)
- PATH environment: Select "Git from the command line and also from 3rd-party software"
- Line ending conversions: Choose "Checkout Windows-style, commit Unix-style"
- Terminal emulator: Use MinTTY (default)
- Default branch name: Override to use "main"
For most other options, the defaults are fine. Just keep clicking "Next"!
- Complete the installation: Click "Install" and wait for it to finish
- Verify installation: Open a new Command Prompt or PowerShell window and run:
git --versionYou should see the Git version number!
Method 2: Using Package Managers
If you use Windows package managers, you can also install Git through:
- Chocolatey:
choco install git - Winget:
winget install Git.Git
🎨 Git Bash
Git for Windows includes "Git Bash", a Unix-style terminal that many developers prefer. You can find it in your Start menu after installation. It provides a consistent command-line experience similar to Mac and Linux.
Installing Git on macOS
macOS usually includes an older version of Git, but we recommend installing a newer version.
Method 1: Using Homebrew (Recommended)
Homebrew is a popular package manager for Mac that makes installing developer tools easy.
- Install Homebrew (if you don't have it):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Install Git using Homebrew:
brew install git- Verify installation:
git --versionMethod 2: Official Git Installer
- Download the installer from git-scm.com/download/mac
- Open the
.dmgfile and follow the instructions - Verify installation in Terminal with
git --version
Method 3: Xcode Command Line Tools
Installing Xcode Command Line Tools will also install Git:
xcode-select --installA popup will appear—click "Install" and agree to the license terms.
🍎 Mac Users
If you plan to do any development on Mac, Homebrew is incredibly useful for installing other tools too. We highly recommend the Homebrew method!
Installing Git on Linux
Most Linux distributions make it easy to install Git using their package manager.
Debian/Ubuntu
# Update package list
sudo apt update
# Install Git
sudo apt install git
# Verify installation
git --versionFedora
# Install Git
sudo dnf install git
# Verify installation
git --versionArch Linux
# Install Git
sudo pacman -S git
# Verify installation
git --versionCentOS/RHEL
# Install Git
sudo yum install git
# Verify installation
git --version🐧 Linux Users
If you're on a different Linux distribution, check your distribution's documentation for the package manager command. Git is available in virtually all Linux repositories!
Step 2: Configure Your Identity
Now that Git is installed, you need to configure it with your name and email. This information is attached to every commit you make, so others know who made which changes.
Important: Git requires this configuration before you can make your first commit. If you skip this step, Git will complain when you try to commit changes!
Set Your Name
This should be your real name or the name you want associated with your work:
git config --global user.name "Your Name"Replace "Your Name" with your actual name, for example:
git config --global user.name "Sarah Johnson"Set Your Email
Use the email address associated with your GitHub account (if you created one):
git config --global user.email "your.email@example.com"For example:
git config --global user.email "sarah.johnson@example.com"GitHub Email Privacy: If you want to keep your email private, GitHub provides a no-reply email address you can use. Find it in your GitHub settings under Emails. It looks like: 123456+username@users.noreply.github.com
Understanding --global
The --global flag means these settings apply to all Git repositories on your computer. You only need to do this once!
If you ever need different settings for a specific project, you can omit --global and run the commands inside that project's directory.
Step 3: Verify Your Configuration
Let's make sure everything is set up correctly.
Check Specific Settings
View your configured name:
git config --global user.nameView your configured email:
git config --global user.emailView All Configuration
See all your Git settings at once:
git config --listThis will show something like:
user.name=Sarah Johnson
user.email=sarah.johnson@example.com
core.editor=code --wait
init.defaultbranch=main
...✅ Configuration Complete!
If you see your name and email when running these commands, you're all set! Git is now configured and ready to use.
Step 4: Additional Useful Configuration
While name and email are required, here are some other settings that will improve your Git experience:
Set Default Branch Name to "main"
Modern Git uses "main" as the default branch name instead of "master":
git config --global init.defaultBranch mainSet Your Preferred Text Editor
Git will open a text editor for commit messages. Set your preferred editor:
# For Visual Studio Code
git config --global core.editor "code --wait"
# For Nano (simple terminal editor)
git config --global core.editor "nano"
# For Vim
git config --global core.editor "vim"
# For Sublime Text
git config --global core.editor "subl -n -w"💡 Editor Recommendation
If you're new to the command line, we recommend VS Code or Nano. Vim and Emacs are powerful but have a steeper learning curve.
Enable Helpful Colors
Make Git output more readable with colors (usually enabled by default):
git config --global color.ui autoSet Up Line Ending Handling
This helps prevent issues when working with people on different operating systems:
# For Windows
git config --global core.autocrlf true
# For Mac/Linux
git config --global core.autocrlf inputWhy this matters: Windows uses different line endings (CRLF) than Mac/Linux (LF). This setting automatically handles the conversion so everyone sees consistent files.
Step 5: Set Up Credential Helper (Optional but Recommended)
Without a credential helper, Git will ask for your GitHub username and password every time you push or pull. Let's fix that!
For Windows
If you installed Git for Windows, the credential manager is already set up. Verify with:
git config --global credential.helperYou should see manager-core or manager.
For macOS
Use the built-in Keychain credential helper:
git config --global credential.helper osxkeychainFor Linux
Set up the cache credential helper:
# Store credentials for 1 hour
git config --global credential.helper cache
# Or store credentials for longer (e.g., 10 hours)
git config --global credential.helper 'cache --timeout=36000'🔐 About Credentials
Note: GitHub no longer accepts password authentication. In a later lesson, we'll set up SSH keys or Personal Access Tokens for secure authentication with GitHub. The credential helper will store whichever method you choose!
Understanding Configuration Levels
Git has three levels of configuration:
1. System Level (All Users)
git config --systemApplies to all users on the computer. Rarely used and requires admin privileges.
2. Global Level (Your User)
git config --globalApplies to all your repositories. This is what we've been using and is the most common level.
3. Local Level (One Repository)
git config --localApplies only to the current repository. Used when you need different settings for a specific project.
Local settings override global settings, and global settings override system settings.
Editing Configuration File Directly (Advanced)
If you prefer, you can edit the configuration file directly instead of using commands:
# Open global config in your default editor
git config --global --editThis opens your global config file (usually located at ~/.gitconfig on Mac/Linux or C:\Users\YourName\.gitconfig on Windows).
The file looks like this:
[user]
name = Sarah Johnson
email = sarah.johnson@example.com
[core]
editor = code --wait
[init]
defaultBranch = main
[color]
ui = autoYou can edit this file manually, but using git config commands is safer for beginners.
Troubleshooting Common Issues
Issue: Command Not Found
Problem: After installation, you get "command not found" or "git is not recognized"
Solution:
- Close and reopen your terminal/command prompt
- On Windows, restart your computer (this updates the PATH)
- Verify Git is in your PATH: on Windows, search for "Environment Variables" and check if Git's bin directory is listed
Issue: Permission Denied
Problem: You get permission denied errors
Solution:
- On Linux/Mac, don't use
sudowith git config commands - Check file permissions on your config file
- Make sure you're not trying to configure system-level settings
Issue: Editor Won't Close
Problem: Git opens Vim and you can't figure out how to exit
Solution:
- Press
Escto enter command mode - Type
:q!and press Enter to quit without saving - Set a different editor as shown above to avoid Vim in the future
Issue: Wrong Name or Email
Problem: You configured the wrong name or email
Solution: Just run the config command again with the correct information—it will overwrite the old value:
git config --global user.name "Correct Name"
git config --global user.email "correct.email@example.com"Testing Your Installation
Let's verify everything is working correctly with a few commands:
Test Your Git Installation
Try these commands to verify your setup
Try these examples:
All commands should work without errors!
Useful Configuration Commands
Here's a quick reference of common config commands:
# View all configuration
git config --list
# View configuration with file origins
git config --list --show-origin
# Get a specific setting
git config user.name
# Set a value
git config --global user.name "Your Name"
# Unset (remove) a value
git config --global --unset user.name
# Edit configuration file directly
git config --global --edit
# Get help on configuration
git config --helpWhat You Can Do Now
With Git installed and configured, you're ready to start using it! Here's a preview of what's coming:
- Create repositories: Initialize Git in your projects
- Make commits: Save snapshots of your work
- View history: See all the changes you've made over time
- Create branches: Try different ideas safely
- Connect to GitHub: Share your work and collaborate
In the next lesson, we'll create your first Git repository and make your first commit!
Key Takeaways
- Check if Git is installed with
git --version - Installation methods vary by OS: official installer, Homebrew, or package managers
- You must configure your name and email before making commits
- Use
--globalflag to apply settings to all repositories - Set your default branch name to "main" for consistency
- Configure a text editor for writing commit messages
- Use credential helpers to avoid typing passwords repeatedly
- Configuration can be system-level, global (user), or local (repository)
- Use
git config --listto view all your settings - If you make mistakes, just run the config command again to fix it
What's Next?
Congratulations! You've successfully installed and configured Git. You now have everything you need to start tracking your projects.
In the next lesson, we'll create your very first Git repository, make some changes, and create your first commits. You'll see Git in action and start building your understanding of the commit workflow!
🎯 Before the Next Lesson
Make sure you can successfully run these commands:
git --version(shows version number)git config user.name(shows your name)git config user.email(shows your email)
If all three work, you're ready to move forward!