Skip to content

Commit 245d8c9

Browse files
committed
content: more on branches, renamed merging
1 parent eab0ef3 commit 245d8c9

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

src/content/lessons/git-branches.md

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ links: {
1414

1515
A **branch** in Git is essentially a moveable pointer to a specific commit.
1616

17-
Branches are incredibly lightweight - creating a branch is just creating a file containing a unique hash
17+
Branches are lightweight - a branch is just a file containing a commit hash.
1818

1919
> Files you commit on one branch are not visible when you switch to another.
2020
@@ -28,6 +28,8 @@ Branches are incredibly lightweight - creating a branch is just creating a file
2828

2929
- **Easy rollback** - Discard experimental work if it doesn't work out
3030

31+
- **Version support** - apply fixes to previous versions
32+
3133
---
3234

3335
## Listing Branches
@@ -76,15 +78,14 @@ git switch -c feature-user-profile
7678
# Good branch names
7779
feature/user-authentication
7880
bugfix/login-timeout
79-
hotfix/security-patch
8081
docs/api-documentation
8182
refactor/database-queries
8283

8384
# Poor branch names
8485
fix
8586
temp
86-
john-branch
87-
new-feature
87+
my-branch
88+
new-stuff
8889
```
8990

9091
---
@@ -107,18 +108,42 @@ git switch feature-user-profile
107108

108109
## The HEAD meta-branch
109110

110-
Git tracks which is current working branch using `HEAD`.
111+
Git tracks the current branch in a *special ref* called `HEAD`.
111112

112113
It is similar to a branch in that it can be used as an argument where-ever a branch is needed.
113114

114-
But it is NOT a real branch - it always points to the current branch (or commit)
115+
But it is NOT a true branch - it points to the current branch
115116

116-
```
117-
# display the contents of the commit
118-
# that is currently checked out
117+
---
118+
119+
![HEAD pointer](https://git-scm.com/book/en/v2/images/head-to-master.png)
120+
121+
> Branches point to commits; HEAD points at a branch
122+
123+
---
124+
125+
All of the following commands
126+
will do the same thing - display the contents of the *commit*
127+
that is pointed to by the *branch*, that is currently **checked-out**
128+
129+
```bash
119130
git show HEAD
131+
132+
git show master
133+
134+
git show f30ab
120135
```
121136

137+
---
138+
139+
## Checkout
140+
141+
The checkout command does 2 main things:
142+
- Changes the branch that `HEAD` points to
143+
- Overwrites the contents of the working directory with
144+
the contents of the commit pointed by the new `HEAD` branch
145+
146+
122147
---
123148

124149
In this example `HEAD` is pointing to the `testing` branch
@@ -128,6 +153,14 @@ which is one commit ahead of `master`:
128153

129154
---
130155

156+
<class-work>
157+
158+
### Replicate the state of the repository from the picture
159+
160+
</class-work>
161+
162+
---
163+
131164
## Renaming Branches
132165

133166
```bash
@@ -234,7 +267,7 @@ git fetch --prune
234267

235268
---
236269

237-
## Branch Lifecycle
270+
## Branch Life-cycle
238271

239272
1. **Create** branch from up-to-date main
240273
2. **Work** on feature with regular commits
File renamed without changes.

0 commit comments

Comments
 (0)