G
GuideDevOps
Lesson 2 of 18

Installing & Configuring Git

Part of the Git & Version Control tutorial series.

Installing Git

macOS

Using Homebrew:

brew install git

Linux (Ubuntu/Debian)

sudo apt-get update
sudo apt-get install git

Linux (Fedora/RHEL)

sudo dnf install git

Windows

Download from git-scm.com and run installer

Verify Installation

git --version
# git version 2.40.0 (or newer)

Initial Configuration

Set Your Identity

# Global configuration
git config --global user.name "John Doe"
git config --global user.email "[email protected]"
 
# Repository-specific
git config user.name "John Doe"
git config user.email "[email protected]"

Check Configuration

git config --list
git config user.name

Configure Your Editor

git config --global core.editor "code --wait"  # VS Code
git config --global core.editor "vim"          # Vim

SSH Key Setup

Generate SSH Key

ssh-keygen -t ed25519 -C "[email protected]"
# Press Enter for default location
# Enter passphrase (optional but recommended)

Add to SSH Agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Add Public Key to GitHub

cat ~/.ssh/id_ed25519.pub
# Copy output and paste in GitHub Settings → SSH Keys

Test Connection

ssh -T [email protected]
# Hi username! You've successfully authenticated

First Repository

Create New Repository

mkdir my-project
cd my-project
git init

This creates .git directory with Git metadata.

Clone Existing Repository

git clone https://github.com/username/repo.git
git clone [email protected]:username/repo.git  # SSH method

First Commit

echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"

Useful Configuration

# Better output
git config --global color.ui true
 
# Default branch name
git config --global init.defaultBranch main
 
# Auto-correct typos
git config --global help.autocorrect 1
 
# Store credentials
git config --global credential.helper cache

Configuration Levels

LevelFileScope
System/etc/gitconfigAll users
Global~/.gitconfigCurrent user
Local.git/configCurrent repo

Troubleshooting

SSH Permission Denied

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh -T [email protected]

Credential Issues

git config --global --unset credential.helper
git config --global credential.helper cache

Wrong User

git config --global user.name "New Name"
git config --global user.email "[email protected]"

title: "Installing & Configuring Git" description: "Setting up your environment and your first Git config." order: 2

Installation

  • Linux (Ubuntu/Debian): `sudo apt update && sudo apt install git`
  • Mac: `brew install git` or install Xcode Command Line Tools.
  • Windows: Download Git for Windows (includes Git Bash).

Initial Configuration

After installing, the first thing you must do is set your identity. This information is attached to every commit you make.

```bash git config --global user.name "Your Name" git config --global user.email "[email protected]" ```

Verify

```bash git --version git config --list ```