Appendix: Quick Setup Script

Save this as setup-git-github.sh and run to quickly set up your environment:

#!/bin/bash

echo "🚀 Git and GitHub Setup Script for macOS"
echo "======================================="

# Install Homebrew if not present
if ! command -v brew &> /dev/null; then
    echo "📦 Installing Homebrew..."
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# Install Git
echo "📦 Installing Git..."
brew install git

# Install GitHub CLI
echo "📦 Installing GitHub CLI..."
brew install gh

# Git configuration
echo "⚙️ Configuring Git..."
read -p "Enter your name: " name
read -p "Enter your email: " email

git config --global user.name "$name"
git config --global user.email "$email"
git config --global init.defaultBranch main
git config --global color.ui auto

# Generate SSH key
echo "🔑 Generating SSH key..."
ssh-keygen -t ed25519 -C "$email" -f ~/.ssh/id_ed25519 -N ""

# Start SSH agent and add key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Copy SSH key to clipboard
pbcopy < ~/.ssh/id_ed25519.pub
echo "📋 SSH public key copied to clipboard!"

# GitHub CLI authentication
echo "🔐 Authenticating with GitHub..."
gh auth login

echo "✅ Setup complete!"
echo ""
echo "Next steps:"
echo "1. Go to GitHub Settings → SSH Keys"
echo "2. Add a new SSH key (already in clipboard)"
echo "3. Test with: ssh -T git@github.com"

Make executable and run:

chmod +x setup-git-github.sh
./setup-git-github.sh

Last Updated: 2024 Version: 1.0

This guide is a living document. Contribute improvements at: [your-repo-url]

Back to top