Installing Git
macOS
Using Homebrew:
brew install gitLinux (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install gitLinux (Fedora/RHEL)
sudo dnf install gitWindows
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 "john@example.com"
# Repository-specific
git config user.name "John Doe"
git config user.email "john@example.com"Check Configuration
git config --list
git config user.nameConfigure Your Editor
git config --global core.editor "code --wait" # VS Code
git config --global core.editor "vim" # VimSSH Key Setup
Generate SSH Key
ssh-keygen -t ed25519 -C "john@example.com"
# Press Enter for default location
# Enter passphrase (optional but recommended)Add to SSH Agent
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519Add Public Key to GitHub
cat ~/.ssh/id_ed25519.pub
# Copy output and paste in GitHub Settings → SSH KeysTest Connection
ssh -T git@github.com
# Hi username! You've successfully authenticatedFirst Repository
Create New Repository
mkdir my-project
cd my-project
git initThis creates .git directory with Git metadata.
Clone Existing Repository
git clone https://github.com/username/repo.git
git clone git@github.com:username/repo.git # SSH methodFirst 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 cacheConfiguration Levels
| Level | File | Scope |
|---|---|---|
| System | /etc/gitconfig | All users |
| Global | ~/.gitconfig | Current user |
| Local | .git/config | Current repo |
Troubleshooting
SSH Permission Denied
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh -T git@github.comCredential Issues
git config --global --unset credential.helper
git config --global credential.helper cacheWrong User
git config --global user.name "New Name"
git config --global user.email "new@example.com"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 "you@example.com" ```
Verify
```bash git --version git config --list ```