Support Free C++ Education
Help us create more high-quality C++ learning content. Your support enables us to build more interactive projects, write comprehensive tutorials, and keep all content free for everyone.
Getting Started
Before you can use Git, you need to install it on your computer. The good news: Git runs on every major operating system, and installation is straightforward.
This guide walks you through installation on Windows, macOS, and Linux, then covers the essential configuration every Git user needs.
Check If Git Is Already Installed
Git might already be on your system. Open a terminal and run:
git --version
If you see a version number (like git version 2.43.0), Git is installed and you can skip to the Configuration section.
If you see "command not found" or similar, continue with the installation instructions for your operating system.
Installing on Windows
Option 1: Git for Windows (Recommended)
Download and install from the official source:
- Go to git-scm.com/downloads/win
- Download the installer for your system (64-bit for most modern computers)
- Run the installer
During installation, you'll see several options:
Select Components: Keep defaults. Make sure "Git Bash Here" is checked.
Default Editor: Choose your preferred editor. If unsure, the default (Vim) works, but you might prefer Notepad++ or VS Code if you have them installed.
Adjusting PATH: Select "Git from the command line and also from 3rd-party software" (middle option). This lets you use Git from any terminal.
HTTPS Transport: Choose "Use the OpenSSL library" (default).
Line Ending Conversions: Choose "Checkout Windows-style, commit Unix-style line endings" (default). This handles the difference between Windows and Unix line endings automatically.
Terminal Emulator: "Use MinTTY" is fine for beginners. Power users might prefer Windows Terminal.
Default Branch Name: Choose "Override the default branch name" and enter main. This uses modern Git conventions.
Other options: Defaults are fine.
After installation, open Git Bash (search for it in Start menu) and verify:
git --version
Option 2: Windows Package Manager
If you use winget (Windows 11 and Windows 10 with app updates):
winget install Git.Git
Then restart your terminal.
Installing on macOS
Option 1: Xcode Command Line Tools
The simplest way. Open Terminal and run:
xcode-select --install
A dialog appears asking to install command line developer tools. Click "Install" and wait for completion.
Verify:
git --version
Option 2: Homebrew (Recommended for Developers)
If you use Homebrew (a popular macOS package manager):
brew install git
This often gives you a more recent version than the Xcode tools.
If you don't have Homebrew, install it first from brew.sh.
Option 3: Official Installer
Download from git-scm.com/downloads/mac and run the installer.
Installing on Linux
Debian/Ubuntu
sudo apt update
sudo apt install git
Fedora
sudo dnf install git
Arch Linux
sudo pacman -S git
Other Distributions
Check your distribution's package manager. Git is available in virtually every Linux distribution's repositories.
After installation, verify:
git --version
First-Time Configuration
Before using Git, configure your identity. This information appears in every commit you make.
Set Your Name
This name appears as the author of your commits:
git config --global user.name "Your Name"
Use your real name or the name you want associated with your code.
Set Your Email
git config --global user.email "your.email@example.com"
This email is public in commits. If you push to GitHub, use the same email as your GitHub account for proper attribution.
Verify Configuration
Check your settings:
git config --list
You should see your name and email in the output.
Set Default Branch Name
Modern Git uses main as the default branch name:
git config --global init.defaultBranch main
This affects new repositories you create. Older tutorials might reference master, but main is now standard.
Choosing an Editor
Git opens a text editor for commit messages and other operations. Set your preferred editor:
For VS Code:
git config --global core.editor "code --wait"
For Notepad++ (Windows):
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
For Nano (simple terminal editor):
git config --global core.editor "nano"
For Vim (terminal, pre-installed on macOS/Linux):
git config --global core.editor "vim"
If you don't set an editor, Git uses your system's default (often Vim on macOS/Linux, Notepad on Windows).
Understanding the Terminal
Git is primarily a command-line tool. If you're new to the terminal, here are essential commands you'll use:
Navigation
# Print working directory (where you are)
pwd
# List files in current directory
ls
# List with details (permissions, dates)
ls -la
# Change directory
cd folder-name
# Go up one directory
cd ..
# Go to home directory
cd ~
File Operations
# Create a new directory
mkdir my-project
# Create a new file (macOS/Linux)
touch filename.txt
# View file contents
cat filename.txt
# Clear the terminal
clear
Windows-Specific Notes
On Windows, Git Bash provides a Unix-like terminal that works with these commands. The Windows Command Prompt uses different commands (dir instead of ls, for example), but Git Bash is more consistent with tutorials and documentation.
Creating Your First Test
Let's verify everything works:
# Create a test folder
mkdir git-test
cd git-test
# Initialize a Git repository
git init
# Check status
git status
You should see:
Initialized empty Git repository in /path/to/git-test/.git/
And git status should show:
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
Git is working. You can delete this test folder or use it for practice.
Helpful Aliases
Git aliases create shortcuts for common commands. These are optional but convenient:
# Shorter status command
git config --global alias.st status
# Shorter commit command
git config --global alias.ci commit
# Prettier log output
git config --global alias.lg "log --oneline --graph --decorate"
After setting these, you can use:
git stinstead ofgit statusgit ciinstead ofgit commitgit lgfor a compact, visual log
Credential Storage
When working with remote repositories (like GitHub), Git asks for your credentials. To avoid typing them repeatedly:
On macOS:
git config --global credential.helper osxkeychain
On Windows:
git config --global credential.helper wincred
On Linux:
git config --global credential.helper cache
The cache helper on Linux stores credentials temporarily (default 15 minutes). For permanent storage, consider using SSH keys, which we cover in Working with GitHub.
Troubleshooting
"git is not recognized as a command" (Windows)
Git wasn't added to your PATH during installation. Either:
- Reinstall Git, selecting "Git from the command line and also from 3rd-party software"
- Use Git Bash instead of Command Prompt
"xcrun: error: invalid active developer path" (macOS)
Xcode command line tools need updating. Run:
xcode-select --install
"Permission denied" errors (Linux)
You might need to use sudo for installation, but never use sudo for Git commands themselves.
Checking Configuration Location
Git config can be set at three levels:
- System:
/etc/gitconfig(all users) - Global:
~/.gitconfig(your user) - Local:
.git/config(specific repository)
Global (--global) is most common. View where settings come from:
git config --list --show-origin
What's Next
Git is installed and configured. You're ready to create your first real repository and start tracking changes.
Next article: Your First Repository - Initialize a project, make commits, and see version control in action.
Keep this article bookmarked for reference. The configuration commands are things you'll set once and rarely need again, but it's helpful to know where to look.
Part of the Git Fundamentals series.
Support Free C++ Education
Help us create more high-quality C++ learning content. Your support enables us to build more interactive projects, write comprehensive tutorials, and keep all content free for everyone.
About the Author
Software engineer and C++ educator passionate about making programming accessible to beginners. With years of experience in software development and teaching, Imran creates practical, hands-on lessons that help students master C++ fundamentals.
Related Articles
Working with GitHub: Remote Repositories and Collaboration
Connect your local Git repository to GitHub. Learn to push, pull, clone, and collaborate with remote...
Git Branches and Merging: Parallel Development Without Chaos
Learn to use Git branches for safe experimentation and parallel development. Create branches, merge...
Understanding Git Commits: Snapshots, History, and Time Travel
Go beyond basic commits. Learn what commits really are, how to write meaningful commit messages, nav...
Article Discussion
Share your thoughts and questions
No comments yet. Be the first to share your thoughts!