Install Git on your system, configure it for professional use, and set up SSH keys for secure authentication with GitHub and other Git hosting services.
Before you can start using Git, you need to install it and configure it properly. A professional Git setup involves more than just running an installer - you'll configure your identity, set up secure authentication, and customize Git to match your workflow.
In this lesson, you'll learn how to install Git on any operating system, configure it correctly from the start, and set up SSH keys so you can securely push code to GitHub, GitLab, and other remote repositories without typing passwords every time.
By the end of this lesson, you'll have a fully functional, professionally configured Git environment ready for real-world development.
Git installation varies by operating system. Here's how to get Git running on your machine.
Windows Installation:
Option 1: Git for Windows (Recommended)
1# Verify installation in PowerShell or Command Prompt
2git --version
3# Output: git version 2.43.0.windows.1Option 2: Windows Package Managers
1# Using winget (Windows 11 / Windows 10)
2winget install Git.Git
3
4# Using Chocolatey
5choco install git
6
7# Using Scoop
8scoop install gitmacOS Installation:
Option 1: Xcode Command Line Tools (Simplest)
1# This installs Git along with other development tools
2xcode-select --installOption 2: Homebrew (Recommended for developers)
1# Install Homebrew first if not installed
2/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3
4# Install Git
5brew install gitOption 3: Official Installer
Download from https://git-scm.com/download/mac
1# Verify installation
2git --version
3# Output: git version 2.43.0Linux Installation:
1# Debian/Ubuntu
2sudo apt update
3sudo apt install git
4
5# Fedora
6sudo dnf install git
7
8# Arch Linux
9sudo pacman -S git
10
11# CentOS/RHEL
12sudo yum install git
13# or for newer versions
14sudo dnf install git
15
16# OpenSUSE
17sudo zypper install git1# Verify installation
2git --version
3# Output: git version 2.43.0After installation, Git needs to know who you are. This identity is attached to every commit you make.
Configuration Levels:
Git has three configuration levels:
--system**: All users on the system (/etc/gitconfig)--global**: Your user account (~/.gitconfig)--local**: Specific repository (.git/config)Each level overrides the previous one.
Required Configuration - Your Identity:
1# Set your name (appears in commit history)
2git config --global user.name "Your Full Name"
3
4# Set your email (MUST match your GitHub/GitLab email for proper attribution)
5git config --global user.email "[email protected]"
6
7# Verify your settings
8git config --global --list⚠️ Important: Use the same email you registered with on GitHub. If you use a different email, your commits won't be linked to your profile.
Recommended Configuration:
1# Set default branch name to 'main' (modern standard)
2git config --global init.defaultBranch main
3
4# Set default text editor
5# VS Code:
6git config --global core.editor "code --wait"
7# Vim:
8git config --global core.editor "vim"
9# Nano:
10git config --global core.editor "nano"
11# Notepad++ (Windows):
12git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
13
14# Enable colored output
15git config --global color.ui auto
16
17# Set up helpful aliases
18git config --global alias.st status
19git config --global alias.co checkout
20git config --global alias.br branch
21git config --global alias.ci commit
22git config --global alias.unstage 'reset HEAD --'
23git config --global alias.last 'log -1 HEAD'
24git config --global alias.visual '!gitk'Line Ending Configuration:
Different operating systems handle line endings differently. Git can auto-convert them:
1# On Windows (convert LF to CRLF on checkout, CRLF to LF on commit)
2git config --global core.autocrlf true
3
4# On macOS/Linux (only convert CRLF to LF on commit, if somehow present)
5git config --global core.autocrlf inputView All Configuration:
1# List all settings and their origins
2git config --list --show-origin
3
4# Check a specific setting
5git config user.name
6git config user.emailSSH keys provide secure, password-free authentication to GitHub, GitLab, and other Git hosting services. This is the professional way to connect.
Why SSH Keys?
Step 1: Check for Existing SSH Keys
1# Check if you already have SSH keys
2ls -la ~/.ssh
3
4# Look for files like:
5# id_rsa (private key) and id_rsa.pub (public key)
6# or id_ed25519 and id_ed25519.pubStep 2: Generate a New SSH Key
1# Ed25519 is the modern, recommended algorithm
2ssh-keygen -t ed25519 -C "[email protected]"
3
4# If your system doesn't support Ed25519, use RSA:
5ssh-keygen -t rsa -b 4096 -C "[email protected]"When prompted:
Step 3: Start the SSH Agent
1# On macOS/Linux:
2eval "$(ssh-agent -s)"
3
4# On Windows (Git Bash):
5eval "$(ssh-agent -s)"
6
7# On Windows PowerShell:
8Start-Service ssh-agentStep 4: Add Your SSH Key to the Agent
1# Add the key
2ssh-add ~/.ssh/id_ed25519
3
4# On macOS, add to Keychain (persists across restarts):
5ssh-add --apple-use-keychain ~/.ssh/id_ed25519Step 5: Add Public Key to GitHub
1# Copy the public key to clipboard
2
3# macOS:
4pbcopy < ~/.ssh/id_ed25519.pub
5
6# Windows (Git Bash):
7cat ~/.ssh/id_ed25519.pub | clip
8
9# Linux (requires xclip):
10xclip -selection clipboard < ~/.ssh/id_ed25519.pub
11
12# Or just display and manually copy:
13cat ~/.ssh/id_ed25519.pubOn GitHub:
Step 6: Test the Connection
1ssh -T [email protected]
2
3# Success message:
4# "Hi username! You've successfully authenticated, but GitHub does not provide shell access."Many developers work with multiple Git accounts (personal, work, client projects). SSH config helps manage this.
Create/Edit SSH Config File:
1# Create or edit the config file
2nano ~/.ssh/configExample Configuration:
1# Default GitHub (Personal)
2Host github.com
3 HostName github.com
4 User git
5 IdentityFile ~/.ssh/id_ed25519_personal
6 IdentitiesOnly yes
7
8# Work GitHub
9Host github-work
10 HostName github.com
11 User git
12 IdentityFile ~/.ssh/id_ed25519_work
13 IdentitiesOnly yes
14
15# GitLab
16Host gitlab.com
17 HostName gitlab.com
18 User git
19 IdentityFile ~/.ssh/id_ed25519_gitlab
20 IdentitiesOnly yes
21
22# Bitbucket
23Host bitbucket.org
24 HostName bitbucket.org
25 User git
26 IdentityFile ~/.ssh/id_ed25519_bitbucket
27 IdentitiesOnly yesUsing Different Accounts:
1# Clone with personal account (default)
2git clone [email protected]:username/repo.git
3
4# Clone with work account
5git clone git@github-work:company/repo.gitPer-Repository Git Config:
1# Inside a work repository, override global settings
2cd ~/work/project
3git config user.email "[email protected]"
4git config user.name "Your Name (Company)"
5
6# Check local config
7git config --local --listConditional Git Config (Advanced):
In ~/.gitconfig, you can apply different settings based on directory:
1[user]
2 name = Personal Name
3 email = [email protected]
4
5# Apply work settings to all repos under ~/work/
6[includeIf "gitdir:~/work/"]
7 path = ~/.gitconfig-workCreate ~/.gitconfig-work:
1[user]
2 name = Work Name
3 email = [email protected]Set up Git like a professional with these additional configurations.
Useful Global Settings:
1# Pull behavior - rebase instead of merge (cleaner history)
2git config --global pull.rebase true
3
4# Push only current branch (safer)
5git config --global push.default current
6
7# Auto-setup remote tracking
8git config --global push.autoSetupRemote true
9
10# Show a summary of diff on commit
11git config --global commit.verbose true
12
13# Enable rerere (remember resolved conflicts)
14git config --global rerere.enabled true
15
16# Set merge tool
17git config --global merge.tool vscode
18git config --global mergetool.vscode.cmd 'code --wait $MERGED'
19
20# Set diff tool
21git config --global diff.tool vscode
22git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE'
23
24# Improved diff algorithm
25git config --global diff.algorithm histogram
26
27# Always sign-off commits (required by some projects)
28git config --global commit.signoff trueHelpful Aliases for Daily Use:
1# Better log visualization
2git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
3
4# Show last commit
5git config --global alias.last "log -1 HEAD --stat"
6
7# Show changes to be committed
8git config --global alias.dc "diff --cached"
9
10# Amend last commit without editing message
11git config --global alias.amend "commit --amend --no-edit"
12
13# Undo last commit (keep changes staged)
14git config --global alias.undo "reset --soft HEAD~1"
15
16# List all branches with last commit date
17git config --global alias.branches "for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(refname:short)'"
18
19# Clean merged branches
20git config --global alias.cleanup "!git branch --merged | grep -v '\*\|main\|master\|develop' | xargs -n 1 git branch -d"Using Aliases:
1# Now you can use:
2git lg # Pretty log graph
3git st # Status
4git co main # Checkout main
5git br # List branches
6git last # Show last commit
7git undo # Undo last commitVerify Your Complete Setup:
1# Check all global configurations
2git config --global --list
3
4# Test that Git works
5mkdir test-repo && cd test-repo
6git init
7echo "Hello Git" > README.md
8git add .
9git commit -m "Initial commit"
10git log
11
12# Clean up
13cd .. && rm -rf test-repoYour Git setup is now complete!
Run this interactive checker to verify your Git installation and configuration is complete and correct.
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>Git Setup Verification Checklist</title>
7 <style>
8 body {
9 font-family: 'Segoe UI', system-ui, sans-serif;
10 background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
11 min-height: 100vh;
12 color: #e0e0e0;
13 padding: 20px;
14 }
15 .container { max-width: 800px; margin: 0 auto; }
16 h1 { text-align: center; color: #f97316; margin-bottom: 10px; }
17 .subtitle { text-align: center; color: #9ca3af; margin-bottom: 30px; }
18
19 .checklist { background: #1f2937; border-radius: 12px; padding: 20px; margin-bottom: 20px; }
20 .check-item {
21 display: flex; align-items: center; gap: 12px;
22 padding: 15px; margin: 10px 0; background: #374151;
23 border-radius: 8px; cursor: pointer;
24 transition: all 0.3s;
25 }
26 .check-item:hover { background: #4b5563; }
27 .check-item.checked { background: #064e3b; }
28 .check-item.checked .checkbox { background: #22c55e; border-color: #22c55e; }
29 .check-item.checked .checkbox::after { content: '✓'; }
30
31 .checkbox {
32 width: 24px; height: 24px; border: 2px solid #6b7280;
33 border-radius: 6px; display: flex; align-items: center;
34 justify-content: center; font-weight: bold; color: white;
35 }
36 .item-content { flex: 1; }
37 .item-title { font-weight: 600; margin-bottom: 4px; }
38 .item-command { font-family: monospace; font-size: 13px; color: #9ca3af; background: #1f2937; padding: 4px 8px; border-radius: 4px; }
39
40 .progress-bar { background: #374151; border-radius: 10px; height: 20px; margin: 20px 0; overflow: hidden; }
41 .progress-fill { background: linear-gradient(90deg, #f97316, #ea580c); height: 100%; transition: width 0.5s; border-radius: 10px; }
42 .progress-text { text-align: center; margin-top: 10px; font-weight: 600; }
43
44 .command-box {
45 background: #0f172a; border-radius: 8px; padding: 15px;
46 margin: 15px 0; font-family: 'Fira Code', monospace; font-size: 14px;
47 }
48 .command-box .comment { color: #6b7280; }
49 .command-box .command { color: #22c55e; }
50 .command-box .output { color: #9ca3af; }
51
52 .section-title { color: #f97316; font-size: 18px; margin: 20px 0 10px; }
53
54 .success-message {
55 background: linear-gradient(135deg, #064e3b, #065f46);
56 border-radius: 12px; padding: 20px; text-align: center;
57 margin-top: 20px; display: none;
58 }
59 .success-message h2 { color: #22c55e; margin-bottom: 10px; }
60 </style>
61</head>
62<body>
63 <div class="container">
64 <h1>Git Setup Verification</h1>
65 <p class="subtitle">Check off each item as you complete your Git setup</p>
66
67 <div class="progress-bar"><div class="progress-fill" id="progress" style="width: 0%"></div></div>
68 <p class="progress-text"><span id="completed">0</span> of <span id="total">8</span> completed</p>
69
70 <h3 class="section-title">1. Installation</h3>
71 <div class="checklist">
72 <div class="check-item" onclick="toggleCheck(this)">
73 <div class="checkbox"></div>
74 <div class="item-content">
75 <div class="item-title">Git Installed</div>
76 <div class="item-command">git --version</div>
77 </div>
78 </div>
79 </div>
80
81 <h3 class="section-title">2. Identity Configuration</h3>
82 <div class="checklist">
83 <div class="check-item" onclick="toggleCheck(this)">
84 <div class="checkbox"></div>
85 <div class="item-content">
86 <div class="item-title">User Name Set</div>
87 <div class="item-command">git config --global user.name "Your Name"</div>
88 </div>
89 </div>
90 <div class="check-item" onclick="toggleCheck(this)">
91 <div class="checkbox"></div>
92 <div class="item-content">
93 <div class="item-title">Email Configured</div>
94 <div class="item-command">git config --global user.email "[email protected]"</div>
95 </div>
96 </div>
97 </div>
98
99 <h3 class="section-title">3. Editor & Tools</h3>
100 <div class="checklist">
101 <div class="check-item" onclick="toggleCheck(this)">
102 <div class="checkbox"></div>
103 <div class="item-content">
104 <div class="item-title">Default Editor Set</div>
105 <div class="item-command">git config --global core.editor "code --wait"</div>
106 </div>
107 </div>
108 <div class="check-item" onclick="toggleCheck(this)">
109 <div class="checkbox"></div>
110 <div class="item-content">
111 <div class="item-title">Default Branch Set to Main</div>
112 <div class="item-command">git config --global init.defaultBranch main</div>
113 </div>
114 </div>
115 </div>
116
117 <h3 class="section-title">4. SSH Authentication</h3>
118 <div class="checklist">
119 <div class="check-item" onclick="toggleCheck(this)">
120 <div class="checkbox"></div>
121 <div class="item-content">
122 <div class="item-title">SSH Key Generated</div>
123 <div class="item-command">ssh-keygen -t ed25519 -C "[email protected]"</div>
124 </div>
125 </div>
126 <div class="check-item" onclick="toggleCheck(this)">
127 <div class="checkbox"></div>
128 <div class="item-content">
129 <div class="item-title">SSH Key Added to GitHub</div>
130 <div class="item-command">Settings → SSH Keys → Add New Key</div>
131 </div>
132 </div>
133 <div class="check-item" onclick="toggleCheck(this)">
134 <div class="checkbox"></div>
135 <div class="item-content">
136 <div class="item-title">SSH Connection Tested</div>
137 <div class="item-command">ssh -T [email protected]</div>
138 </div>
139 </div>
140 </div>
141
142 <div class="success-message" id="success">
143 <h2>🎉 Setup Complete!</h2>
144 <p>Your Git environment is professionally configured and ready for development.</p>
145 </div>
146
147 <div class="command-box">
148 <div class="comment"># Quick verification commands:</div>
149 <div class="command">$ git config --global --list</div>
150 <div class="output">user.name=Your Name</div>
151 <div class="output">[email protected]</div>
152 <div class="output">init.defaultbranch=main</div>
153 <div class="output">core.editor=code --wait</div>
154 </div>
155 </div>
156
157 <script>
158 function toggleCheck(item) {
159 item.classList.toggle('checked');
160 updateProgress();
161 }
162
163 function updateProgress() {
164 const items = document.querySelectorAll('.check-item');
165 const checked = document.querySelectorAll('.check-item.checked');
166 const percentage = (checked.length / items.length) * 100;
167
168 document.getElementById('progress').style.width = percentage + '%';
169 document.getElementById('completed').textContent = checked.length;
170 document.getElementById('total').textContent = items.length;
171
172 if (checked.length === items.length) {
173 document.getElementById('success').style.display = 'block';
174 } else {
175 document.getElementById('success').style.display = 'none';
176 }
177 }
178 </script>
179</body>
180</html>This interactive checklist helps you verify your Git setup:
1. Installation Verification
2. Identity Configuration
3. Editor & Tools
4. SSH Authentication
Pro Tips:
ssh -T [email protected]Now that Git is installed and configured, you're ready to start using it! In the next lesson, we'll create your first Git repository, learn the core workflow of init, add, and commit, and understand how Git tracks changes. You'll make your first commits and start building version control muscle memory.
Your progress is saved in this browser, on this device only.