Skip to content

Commit 035d1d5

Browse files
committed
init git by example book
0 parents  commit 035d1d5

29 files changed

Lines changed: 4453 additions & 0 deletions

.github/workflows/build-pdf.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Build PDF
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
build-pdf:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout source
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: "3.12"
24+
25+
- name: Install dependencies
26+
run: pip install reportlab markdown beautifulsoup4 Pygments
27+
28+
- name: Get short commit hash
29+
id: vars
30+
run: echo "short_sha=$(git rev-parse --short=6 HEAD)" >> "$GITHUB_OUTPUT"
31+
32+
- name: Build PDF
33+
run: python scripts/build_pdf.py "gitbyexample-${{ steps.vars.outputs.short_sha }}.pdf"
34+
35+
- name: Publish to pdf branch
36+
run: |
37+
PDF_FILE="gitbyexample-${{ steps.vars.outputs.short_sha }}.pdf"
38+
39+
# Save the PDF outside the working tree
40+
cp "$PDF_FILE" /tmp/"$PDF_FILE"
41+
42+
git config user.name "github-actions[bot]"
43+
git config user.email "github-actions[bot]@users.noreply.github.com"
44+
45+
# Switch to pdf branch (fetch existing or create orphan)
46+
if git ls-remote --heads origin pdf | grep -q pdf; then
47+
git fetch origin pdf
48+
git checkout pdf
49+
else
50+
git checkout --orphan pdf
51+
git rm -rf . 2>/dev/null || true
52+
git clean -fd
53+
fi
54+
55+
# Copy the new PDF in
56+
cp /tmp/"$PDF_FILE" .
57+
58+
# Clean old PDFs, keep last 10
59+
ls -t gitbyexample-*.pdf 2>/dev/null | tail -n +11 | xargs -r rm -f
60+
61+
# Write README for the pdf branch
62+
cat > README.md << 'EOF'
63+
# Git By Example — PDF Builds
64+
65+
This branch contains auto-generated PDF builds of the book.
66+
67+
Each push to `main` produces a new PDF named `gitbyexample-<commit>.pdf`.
68+
69+
📥 **Download the latest**: check the most recent file below.
70+
EOF
71+
sed -i 's/^ //' README.md
72+
73+
git add README.md gitbyexample-*.pdf
74+
git commit -m "pdf: build from ${GITHUB_SHA::6}" || echo "No changes to commit"
75+
git push origin pdf

01-getting-started.md

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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

Comments
 (0)