Skip to content

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

  1. Download Installer

  2. 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 installation
  3. Verify 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.Git

macOS Installation

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 --version

Method 2: Official Installer

  1. Visit Git Official Website
  2. Download the .dmg file
  3. Double-click the package and follow instructions

Method 3: Xcode Command Line Tools

bash
# Install Xcode Command Line Tools (includes Git)
xcode-select --install

Linux Installation

Ubuntu/Debian

bash
# Update package list
sudo apt update

# Install Git
sudo apt install git

# Verify installation
git --version

CentOS/RHEL/Fedora

bash
# CentOS/RHEL 7
sudo yum install git

# CentOS/RHEL 8+ or Fedora
sudo dnf install git

# Verify installation
git --version

Arch Linux

bash
# Install Git
sudo pacman -S git

# Verify installation
git --version

Compiling 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 --version

Basic 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.email

Notes:

  • Username can be in English or other languages.
  • Email should be a real email, especially if you want to match it with GitHub, etc.
  • --global means 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 false

Configure 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

Content is for learning and research only.