Books/Git Essentials/Setting Up Git

    Setting Up Git

    Setting Up Git

    Let's get Git installed and configured on your computer. This only takes a few minutes.

    Installing Git

    On macOS

    Git usually comes pre-installed on macOS. Open your terminal and check:

    git --version

    If you see a version number like git version 2.39.0, you're good! If not, install it by:

    1. Installing the Xcode Command Line Tools: xcode-select --install
    2. Or downloading from git-scm.com

    On Windows

    1. Download Git from git-scm.com
    2. Run the installer — the default options are fine for beginners
    3. Open Git Bash (installed with Git) or your terminal

    On Linux

    Use your package manager:

    # Ubuntu / Debian
    sudo apt install git
    
    # Fedora
    sudo dnf install git

    Verify the Installation

    After installing, verify Git works:

    git --version

    You should see something like:

    git version 2.43.0
    

    What to ask your AI: "I'm trying to install Git but I'm getting an error: [paste the error]. Can you help?"

    Configure Your Identity

    Git needs to know who you are. Every commit you make includes your name and email. Set these up:

    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"

    Replace the values with your actual name and the email you use (or plan to use) for GitHub.

    Why This Matters

    • Your name and email appear in every commit you make
    • If you use GitHub, use the same email as your GitHub account so your commits are linked to your profile
    • The --global flag means this applies to all your Git projects

    Verify Your Configuration

    Check that everything is set correctly:

    git config --global --list

    You should see:

    user.name=Your Name
    user.email=you@example.com
    

    Optional: Set Your Default Editor

    When Git needs you to type a message (like a commit message), it opens a text editor. By default, this is often Vim, which can be confusing for beginners.

    Set it to something friendlier:

    # Use VS Code
    git config --global core.editor "code --wait"
    
    # Use nano (simpler terminal editor)
    git config --global core.editor "nano"

    Optional: Set Default Branch Name

    Modern convention uses main instead of master as the default branch name:

    git config --global init.defaultBranch main

    Quick Setup Checklist

    Here's everything in one place:

    # Check Git is installed
    git --version
    
    # Set your identity
    git config --global user.name "Your Name"
    git config --global user.email "you@example.com"
    
    # Set default branch name
    git config --global init.defaultBranch main
    
    # Verify
    git config --global --list

    What's Next?

    Git is installed and configured. In the next tutorial, you'll create your first Git repository!

    What to ask your AI: "I've set up Git. Can you walk me through creating my first repository step by step?"


    🌐 www.genai-mentor.ai