Git Installation and Configuration
This chapter will guide you through installing Git on different operating systems and performing basic configurations to get ready for learning.
Git Installation
Windows Installation
Method 1: Official Installer (Recommended)
Download Installer
- Visit Git Official Website
- Download the version suitable for your system (32-bit or 64-bit)
Installation Steps
1. Double-click the downloaded .exe file 2. Select installation path (default recommended) 3. Select components (default recommended) 4. Select Start Menu folder 5. Choose default editor (VS Code or Notepad++ recommended) 6. Adjust PATH environment (Select "Git from the command line and also from 3rd-party software") 7. Choose HTTPS transport backend (Use default OpenSSL) 8. Configure line ending conversions (Select "Checkout Windows-style, commit Unix-style line endings") 9. Configure terminal emulator (Select "Use MinTTY") 10. Configure extra options (Keep defaults) 11. Finish installationVerify Installation
bash# Open Command Prompt or PowerShell git --version
Method 2: Package Managers
powershell
# Using Chocolatey
choco install git
# Using Scoop
scoop install git
# Using Winget
winget install Git.GitmacOS Installation
Method 1: Homebrew (Recommended)
bash
# Install Homebrew (if not installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Git
brew install git
# Verify installation
git --versionMethod 2: Official Installer
- Visit Git Official Website
- Download the .dmg file
- Double-click the package and follow instructions
Method 3: Xcode Command Line Tools
bash
# Install Xcode Command Line Tools (includes Git)
xcode-select --installLinux Installation
Ubuntu/Debian
bash
# Update package list
sudo apt update
# Install Git
sudo apt install git
# Verify installation
git --versionCentOS/RHEL/Fedora
bash
# CentOS/RHEL 7
sudo yum install git
# CentOS/RHEL 8+ or Fedora
sudo dnf install git
# Verify installation
git --versionArch Linux
bash
# Install Git
sudo pacman -S git
# Verify installation
git --versionCompiling from Source (All Linux Distributions)
bash
# Install dependencies
sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libreadline-dev autoconf build-essential gettext libtool
# Download source
wget https://github.com/git/git/archive/v2.40.0.tar.gz
tar -xzf v2.40.0.tar.gz
cd git-2.40.0
# Compile and install
make configure
./configure --prefix=/usr/local
make all
sudo make install
# Verify installation
git --versionBasic Configuration
After installation, some basic configurations are needed to use Git normally.
Configure User Information
This is mandatory before using Git, as every commit uses this information:
bash
# Configure username
git config --global user.name "Your Name"
# Configure email
git config --global user.email "your.email@example.com"
# Check configuration
git config --global user.name
git config --global user.emailNotes:
- Username can be in English or other languages.
- Email should be a real email, especially if you want to match it with GitHub, etc.
--globalmeans this configuration applies to all repositories on your system.
Configure Default Editor
Git needs to open an editor for certain operations. You can configure your favorite one:
bash
# Configure VS Code as default editor
git config --global core.editor "code --wait"
# Configure Vim as default editor
git config --global core.editor vim
# Configure Nano as default editor
git config --global core.editor nano
# Configure Notepad++ (Windows)
git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"Configure Line Ending Handling
Different operating systems use different characters for line endings. Git can handle this automatically:
bash
# Recommended for Windows
git config --global core.autocrlf true
# Recommended for macOS/Linux
git config --global core.autocrlf input
# If the team uses the same system, you can turn off auto conversion
git config --global core.autocrlf falseConfigure Default Branch Name
Since Git 2.28, you can configure the default branch name:
bash
# Set default branch name to main
git config --global init.defaultBranch main