Skip to content

๐Ÿ› ๏ธ Installation & Setup โ€‹

Installing Git โ€‹

Windows Users โ€‹

The easiest way for Windows users is to download the official installer. Go to https://git-scm.com, download, and click Next through the installation. During installation, there's an option called "Adjusting your PATH environment" โ€” it's recommended to select Git from the command line and also from 3rd-party software.

๐Ÿ’ก Tip: After installing on Windows, you'll get Git Bash, which is a Linux-like terminal where you can use Linux-style commands. It's highly recommended to use it instead of CMD or PowerShell for Git operations.

macOS Users โ€‹

macOS users can simply type in the terminal:

bash
# macOS will automatically prompt you to install Xcode Command Line Tools
git --version
git version 2.39.5 (Apple Git-154)

Or install the latest version with Homebrew:

bash
brew install git

Linux Users โ€‹

Linux users have it even easier โ€” just use your package manager:

bash
# Ubuntu / Debian
sudo apt update && sudo apt install git

# CentOS 8+ / Fedora (CentOS 7 uses sudo yum install git)
sudo dnf install git

# Arch Linux (you're power users โ€” you probably don't need my help)
sudo pacman -S git

After installation, verify:

bash
git --version
git version 2.43.0

Initial Configuration โ€” Introducing Yourself โ€‹

After installing Git, the first thing to do is tell it who you are. It's like going to the gym for the first time โ€” you need to get a membership card first:

bash
# Set your name (will appear in every commit record)
git config --global user.name "Your Name"

# Set your email (same as above)
git config --global user.email "your.email@example.com"

โš ๏ธ Warning: --global is a global configuration, meaning all Git repositories on your computer will use this name and email. If you want to use different identities for work and personal projects, remove --global and set it individually in each repository directory.

Configuration Levels โ€‹

Git configuration has three levels, like wearing three layers of clothing โ€” from inner to outer, with decreasing priority:

LevelFlagConfig file locationScope
System--system/etc/gitconfigAll users and all repositories on the system
Global--global~/.gitconfigAll repositories for the current user
Repository--local (default).git/configCurrent repository only
bash
# View all configuration
git config --list
user.name=Your Name
user.email=your.email@example.com
core.editor=vim
color.ui=auto
init.defaultBranch=main

# View a specific configuration
git config user.name
Your Name

Some Useful Default Configurations โ€‹

bash
# Set default branch name to main (Git 2.28+)
git config --global init.defaultBranch main

# Set default editor (options: vim / nano / code)
git config --global core.editor "code --wait"

# Enable colored output in Git (makes it look nice!)
git config --global color.ui auto

# Set pull to use rebase by default (advanced, covered later)
git config --global pull.rebase true

# Configure useful aliases (detailed in advanced tips chapter)
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lg "log --oneline --graph --all"

Setting Up SSH Keys โ€” Your Key to GitHub โ€‹

When you start using GitHub or GitLab, you'll need to authenticate every push/pull. Using HTTPS requires entering your password every time, which gets annoying fast. SSH keys are like a dedicated key โ€” once set up, you won't need to enter your password each time.

bash
# Generate SSH key pair
ssh-keygen -t ed25519 -C "your.email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/yourname/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Your identification has been saved in /home/yourname/.ssh/id_ed25519
Your public key has been saved in /home/yourname/.ssh/id_ed25519.pub

# View the public key content
cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG7x... your.email@example.com

๐Ÿ’ก Tip: Copy the public key content from above, go to GitHub โ†’ Settings โ†’ SSH and GPG keys โ†’ New SSH key, and paste it in. From then on, when you use the SSH address (git@github.com:username/repo.git) to clone repositories, you won't need to enter a password.