|
| 1 | +# Chapter 1 — Getting Started |
| 2 | + |
| 3 | +## Installing Git |
| 4 | + |
| 5 | +### macOS |
| 6 | + |
| 7 | +```bash |
| 8 | +# Option 1: Xcode Command Line Tools (easiest) |
| 9 | +xcode-select --install |
| 10 | + |
| 11 | +# Option 2: Homebrew |
| 12 | +brew install git |
| 13 | +``` |
| 14 | + |
| 15 | +### Linux (Debian/Ubuntu) |
| 16 | + |
| 17 | +```bash |
| 18 | +sudo apt update |
| 19 | +sudo apt install git |
| 20 | +``` |
| 21 | + |
| 22 | +### Linux (Fedora) |
| 23 | + |
| 24 | +```bash |
| 25 | +sudo dnf install git |
| 26 | +``` |
| 27 | + |
| 28 | +### Windows |
| 29 | + |
| 30 | +Download the installer from [git-scm.com](https://git-scm.com/download/win), or use: |
| 31 | + |
| 32 | +```powershell |
| 33 | +winget install Git.Git |
| 34 | +``` |
| 35 | + |
| 36 | +### Verify Installation |
| 37 | + |
| 38 | +```bash |
| 39 | +git --version |
| 40 | +``` |
| 41 | + |
| 42 | +``` |
| 43 | +git version 2.44.0 |
| 44 | +``` |
| 45 | + |
| 46 | +## Configuring Git |
| 47 | + |
| 48 | +Before your first commit, tell Git who you are. |
| 49 | + |
| 50 | +### Example: Set your identity |
| 51 | + |
| 52 | +```bash |
| 53 | +git config --global user.name "Dariush Abbasi" |
| 54 | +git config --global user.email "dariush@example.com" |
| 55 | +``` |
| 56 | + |
| 57 | +🧠 **What happened?** Git wrote these values to `~/.gitconfig`. Every commit you make will be stamped with this name and email. |
| 58 | + |
| 59 | +### Example: See your config |
| 60 | + |
| 61 | +```bash |
| 62 | +git config --list |
| 63 | +``` |
| 64 | + |
| 65 | +``` |
| 66 | +user.name=Dariush Abbasi |
| 67 | +user.email=dariush@example.com |
| 68 | +``` |
| 69 | + |
| 70 | +### Example: Set your default editor |
| 71 | + |
| 72 | +```bash |
| 73 | +git config --global core.editor "vim" |
| 74 | +``` |
| 75 | + |
| 76 | +Other popular choices: `"code --wait"` (VS Code), `"nano"`, `"subl -n -w"` (Sublime Text). |
| 77 | + |
| 78 | +### Example: Set default branch name |
| 79 | + |
| 80 | +```bash |
| 81 | +git config --global init.defaultBranch main |
| 82 | +``` |
| 83 | + |
| 84 | +🧠 **What happened?** New repositories you create with `git init` will use `main` instead of `master` as the default branch name. |
| 85 | + |
| 86 | +## Creating Your First Repository |
| 87 | + |
| 88 | +### Example: Initialize a new repo |
| 89 | + |
| 90 | +```bash |
| 91 | +mkdir my-project |
| 92 | +cd my-project |
| 93 | +git init |
| 94 | +``` |
| 95 | + |
| 96 | +``` |
| 97 | +Initialized empty Git repository in /home/you/my-project/.git/ |
| 98 | +``` |
| 99 | + |
| 100 | +### Example: See what Git created |
| 101 | + |
| 102 | +```bash |
| 103 | +ls -la .git/ |
| 104 | +``` |
| 105 | + |
| 106 | +``` |
| 107 | +drwxr-xr-x HEAD |
| 108 | +drwxr-xr-x config |
| 109 | +drwxr-xr-x hooks/ |
| 110 | +drwxr-xr-x objects/ |
| 111 | +drwxr-xr-x refs/ |
| 112 | +``` |
| 113 | + |
| 114 | +🧠 **What happened?** Git created a hidden `.git/` directory. This single folder *is* your repository — all history, branches, and configuration live inside it. Your working directory is just a checkout of one version. |
| 115 | + |
| 116 | +## Cloning an Existing Repository |
| 117 | + |
| 118 | +### Example: Clone a repo from GitHub |
| 119 | + |
| 120 | +```bash |
| 121 | +git clone https://github.com/boringcollege/git-by-example.git |
| 122 | +cd git-by-example |
| 123 | +``` |
| 124 | + |
| 125 | +``` |
| 126 | +Cloning into 'git-by-example'... |
| 127 | +remote: Enumerating objects: 42, done. |
| 128 | +remote: Total 42 (delta 0), reused 0 (delta 0) |
| 129 | +Receiving objects: 100% (42/42), done. |
| 130 | +``` |
| 131 | + |
| 132 | +🧠 **What happened?** Git downloaded the entire repository — all files, all branches, all history — to your machine. You now have a full, independent copy. |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | +[Next: Chapter 2 — The Basics →](02-the-basics.md) |
0 commit comments