* [PATCH] doc: add tutorial on branches for beginners
@ 2026-11-09 21:33 Julia Evans via GitGitGadget
2026-11-09 21:56 ` Junio C Hamano
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: Julia Evans via GitGitGadget @ 2026-11-09 21:33 UTC (permalink / raw)
To: git; +Cc: Patrick Steinhardt, D. Ben Knoble, Julia Evans, Julia Evans
From: Julia Evans <julia@jvns.ca>
Because Git's branches are so flexible and the meaning of a branch is
only what people assign to it, it's important to talk about some of the
social context about branches. Do this in two ways:
1. Introduce some imaginary characters who are learning branches for the
first time and examples of workflows they might use. Test readers
said this was helpful because it helped them see different ways
they might use branches.
2. Explain the importance of a "main" or "master" branch in many
projects, and give a few examples of how projects might use it.
On `git log`:
- Use the output of `git log --graph` to visualize branches instead of
a more abstract ASCII diagram, since it serves a double purpose of
teaching people how to read `git log`'s output.
But also mention that folks may prefer to use a GUI to visualize
branches.
- Include two sections to explain the output of `git log`, since several
test readers found it very hard to understand. In that explanation,
only explain `HEAD` fairly briefly and instead keep the focus on the
idea of a "current branch", since that's the term Git's UI normally
uses.
On the conceptual introduction at the beginning:
- One of the biggest issues with explaining branches is that there are 3
ways in Git to think of branches and it's not straightforward to
explain how to reconcile them:
1. just the commits that "branch off"
2. the latest commit on the branch
3. the full history since the beginning of time
Handle this by starting with the "tree" metaphor where branches
"branch off" a central trunk (way 1), since this makes sense with how
people actually want to use branches. Point out some issues with the
tree metaphor and talk about how it relates to the way Git represents
branches (way 2).
- Avoid using computer science jargon, because it's a major barrier to
folks without a CS background. It's not useful or realistic to teach
most beginners the term "directed acyclic graph" just so they can
learn branches. Mention the term "directed acyclic graph" briefly in a
note for folks who are already familiar with that term and link folks
to the data model if they'd like more information.
- Include some basic facts about commits. Folks seemed to find this
helpful, one person said they didn't realize it would be so hard to
change their email address later.
To keep it readable:
- Don't assume that the reader has read `gittutorial`, and instead
refer back to it explicitly if it's relevant.
- Always include the output for every command. Test readers said
this was helpful.
Other choices about material that is/isn't included:
- `git-prompt.sh` (yes): Mention how important it is to be aware
what branch you're on, and suggest using `git-prompt.sh`. Link to
git-prompt.sh on GitHub since several test readers couldn't find it on
their machine. The test readers liked this.
- fast-forward merges (yes): Explain the difference between a fast-forward
merge and a merge commit by giving examples of what each one looks
like.
- upstreams/rebase (no): Don't explain what an upstream is or introduce
rebase, since we're already introducing a lot of concepts. Instead
include a "Where to learn more" section with some pointers to where to
continue learning.
- GUIs (yes): Some readers wanted a suggestion for what GUI to use. It's
very hard to suggest an appropriate GUI because there are so many and
so many of them are not open source, but give a couple of suggestions
of open source tools that seem to be popular with the community. Also
mention that many non-open-source IDEs have built-in Git integrations
for folks who are already using those tools who might not be aware,
since they're a popular way to use Git.
Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Julia Evans <julia@jvns.ca>
---
doc: add tutorial on branches for beginners
Some self-review comments:
* The section on GUIs is tough to write because a lot of the popular
GUIs are proprietary to some extent. Might remove it if that seems
like the best way.
* When the new gittutorial.adoc lands I think it would be good to add a
little table of contents to the top of it to match this one's TOC.
Thanks to Mario (bavarianbidi), Johnny, Ken Wells, Yatin Lala, Valentin
Bachem, Ozgur Dincer, Ken Wells, matsch, and all the other test readers
for giving feedback on this. We got 70 comments from 16 people.
* Here's the overall feedback from the test readers so far (from "Any
other feedback?")
* As git with all the different concepts, and everything builds on each
other is often for new learners hard to follow, I really liked the
scope of the tutorial. Just focusing on branches and everything else
might be relevant later.
* This is so good!
* Thanks for doing this, it's greatly appreciated.
* It went very fluent. I was surprised at how quickly I was progressing
in the text. How the important thing is that I'm going to use what
I've learned in practice. A tutorial cannot help directly with that;
It can only motivate. Maybe it would be nice to ass a sentence or two
on that.
* Thank you for what you do! 🫶
* This is the best tutorial for git branches. It was easy to follow and
I learned so much. I really appreciated the way that the steps flowed
into each other and built off of previous steps, and all the example
output matched what I saw on my machine. Up until now I've just been
blindly following other people's instructions on how to manage
branches, but I finally feel like I get it now. Especially with the
different examples at the end; I can see myself in almost all of them
and it has given me some ideas on how to manage my small-time
projects. Like for modifying other people's repositories, I don't
have to keep making new directories, I can just make a new branch and
push that branch to my repo! It was such a huge confidence boost to
be able to look at the different use cases and be like "I can do that
one here, and that one there!" I don't know what could be done to
make it better. I might end up printing this out and putting it on
the wall for when I'm working on stuff later.
* I am German. Most of the tutorial was understandable and clear.
* Not for this one, but I'd love a tutorial on worktrees.
* Very concise, I learned something new.
* Really enjoying and appreciating these tutorials, thanks very much
* The whole tutorial is quite readable and helpful. :)
* I'm confused of using git switch. I always did what described in the
tutorial using git checkout...
* Thank you for this and the previous tutorial! I've long been
interested in using git but found the complete documentation a bit
overwhelming. You're breaking it down into easily digestible chunks
and I really appreciate it!
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2307%2Fjvns%2Ftutorial-branches-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2307/jvns/tutorial-branches-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2307
Documentation/Makefile | 1 +
Documentation/gittutorial-branches.adoc | 940 ++++++++++++++++++++++++
Documentation/meson.build | 1 +
command-list.txt | 1 +
4 files changed, 943 insertions(+)
create mode 100644 Documentation/gittutorial-branches.adoc
diff --git a/Documentation/Makefile b/Documentation/Makefile
index b574ca2044..4f3fc9a97f 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -65,6 +65,7 @@ MAN7_TXT += gitremote-helpers.adoc
MAN7_TXT += gitrevisions.adoc
MAN7_TXT += gitsubmodules.adoc
MAN7_TXT += gittutorial-2.adoc
+MAN7_TXT += gittutorial-branches.adoc
MAN7_TXT += gittutorial.adoc
MAN7_TXT += gitworkflows.adoc
diff --git a/Documentation/gittutorial-branches.adoc b/Documentation/gittutorial-branches.adoc
new file mode 100644
index 0000000000..4c804f8b16
--- /dev/null
+++ b/Documentation/gittutorial-branches.adoc
@@ -0,0 +1,940 @@
+gittutorial-branches(7)
+=======================
+
+NAME
+----
+gittutorial-branches - How to use branches
+
+DESCRIPTION
+-----------
+
+This is part of a 2-part series on Git for beginners:
+
+- Part 1 (linkgit:gittutorial[7]): Introduction to commits and `git push`
+- Part 2 (you are here): Introduction to branches
+
+Meet some example Git users
+---------------------------
+
+To start, we're going to introduce a few imaginary people who are learning
+to use Git branches for the first time. This is because people use
+branches differently in different situations, so it might be useful for
+you to think about which is closest to your situation.
+
+1. Abdul is making his first contribution to Python, a large open
+ source project.
+2. Betsy is a Go developer for a social media website which has 100
+ other software developers. All of her changes need to be reviewed by a
+ coworker before they're released.
+3. Carmen and Daniela are building a website for their local cat
+ shelter. They're the only two people on the project.
+4. Emilia is using Git on her own to write her PhD thesis with LaTeX.
+
+Why use branches?
+-----------------
+
+Branches are a tool to organize your work and collaborate. For example,
+if you're working on a website, you might be working on multiple
+unrelated changes at the same time, like:
+
+* an update to the FAQ
+* making the website faster
+* adding a translation into Bengali
+
+With branches, you can work on each change at its own pace without them
+interfering with each other.
+
+The "tree" mental model of branches
+-----------------------------------
+
+A useful mental model for Git branches is a tree where the "trunk"
+is the main branch, and there are other branches branching "off" of
+main.
+
+Each of the branches branching off has only a few commits of their own.
+When you finish working on a branch, you can merge its commits back into
+the main branch. This is where the metaphor starts to break down: in a
+real tree, branches that branch off from the trunk don't merge back in
+later, but in Git they can.
+
+For example, here's an ASCII art diagram of a Git repository. The most
+recent commits are at the top. The main branch is in the center and the
+others come off the sides.
+
+---------
+ \ |
+ \| /
+ |/
+ |
+ |
+ |
+---------
+
+This mental model doesn't represent every single thing you can do with
+Git branches, but you can go a long way with it.
+
+[NOTE]
+When the Git documentation uses the word "tree", it means something more
+like "directory tree of files", which is a completely different concept.
+If you want some jargon: the computer science term for "a tree where the
+branches can come back together" is "directed acyclic graph".
+
+The main branch
+---------------
+
+When you run `git init`, Git creates a default branch. Usually this is
+called `main` or `master`. Git mostly doesn't treat this branch in any
+special way (you could even delete that branch if you really want!),
+but for most people using Git this branch does have a special meaning.
+For example:
+
+* In an open source project like Python, the "main" branch might have
+ changes that the maintainers have approved to be in a future release
+* A website's "main" branch might be deployed to the server every time
+ it's updated
+* A PhD student's "main" branch might have the latest version of their
+ PhD thesis
+
+When joining a new project, it's important to understand how that
+project uses its main branch.
+
+In this tutorial we'll call this branch `main`.
+
+Some important facts about Git commits
+--------------------------------------
+
+Before explaining how branches work, here are some important facts about
+Git commits.
+
+**Every commit has an ID**. The ID is made of the numbers 0-9 and letters
+a-f, for example `501584c1bf29ab88e815c09ffb99c887da81241c`. You can
+find the current commit's ID by running `git log`: it's on the first
+line. In this tutorial you're going to see a lot of "short" commit IDs
+(for example `501584c`), which are the first 7 characters or so of the
+commit ID.
+
+**Commits never change**. If you have a commit ID, then the files,
+author, and history of that commit with that ID will never change in any
+way. This is one of Git's biggest strengths, but it also has drawbacks.
+It guarantees that if you have a commit's ID then you can always get
+back its exact contents, but it also makes it difficult to change old
+commits. For example, if someone changes their email address and wants
+to update it on their old commits, it can be very disruptive. You'd need
+to replace all the old commits with new commits with a different email
+address.
+
+**Every commit has a parent** (except the first commit).
+This means that if you have a commit ID, you can follow the pointers to
+the commit's parent(s) to get the whole history of the project up to that
+point.
+
+See linkgit:gitdatamodel[7] for more about how Git represents commits.
+
+
+How Git represents branches
+---------------------------
+
+Even though the way people think about the "main" branch and other
+branches is quite different (one is the "trunk", the others "branch off"
+of main), Git represents all branches in the same way.
+
+Git stores branches as a name and a commit ID. They're stored in the
+`.git` directory in your local Git repository, for example:
+
+----
+main: 37634fd
+add-fruits: cd4bb48
+----
+
+At first, this might seem totally unrelated to the "tree" mental model
+we talked about before. But because every commit has a reference to its
+parent, Git can follow the links from a commit to its parent to get the
+structure (the "tree") of the whole repository.
+
+For example, in this ASCII diagram, the commit below a commit is its
+parent:
+
+-------
+ * cd4bb48 (latest 'add-fruits' commit) Add fruit list
+ /
+* 37634fd (latest 'main' commit) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-------
+
+Branches are very cheap to create: when you create a new branch, Git
+just needs to store one commit ID. But this also means that we don't
+always know the history of how a branch evolved over time. For example
+`Another update to README.md` could originally have been created on a
+different branch that was deleted after merging it into `main`.
+
+The practical part
+------------------
+
+Now let's talk about how to actually use branches.
+
+This tutorial is from the point of view of someone who's using branches
+to organize their own work, because it's simpler. There are some
+examples at the end of how this might change if you're using Git to
+collaborate, like one of the example users at the beginning.
+
+Step 1: Create an empty repository with two commits
+---------------------------------------------------
+
+Before we start working with branches, we need a Git repository to work
+with.
+
+First, create an empty directory, move into it, and start a new Git repository:
+
+----
+mkdir myproject
+cd myproject
+git init
+----
+
+Then open your text editor and create a file called `README.md`, with
+these contents:
+
+-----
+This is an example file.
+It has two lines.
+-----
+
+Then add the file and commit it, by running these commands:
+
+----
+git add README.md
+git commit -m "Initial commit"
+----
+
+Next, edit README.md and make another commit, like this:
+
+----
+git commit -am "Update README.md"
+----
+
+`git commit -am` commits the current version of all files that Git is
+tracking.
+
+Now we're set up and we can start creating branches.
+
+Step 2: Find your current branch
+--------------------------------
+
+In Git, you normally have a "current branch". You can see your current
+branch by running `git status`. It's usually on the first line, like this:
+
+----
+$ git status
+
+On branch main
+----
+
+Step 3: Look at the commits on your current branch
+--------------------------------------------------
+
+Run this command to get a list of all commits on your current
+branch.
+
+
+----
+git log --oneline
+----
+
+The output should look something like this, though with
+different commit IDs:
+
+----
+e9c0b17 (HEAD -> main) Update README.md
+2e018a5 Initial commit
+----
+
+In this tutorial, we're going to use `git log --oneline` over and over
+again to visualize our branch. If you have a Git GUI installed, its
+visualization might be easier to read.
+See <<guis,GUI tools>> for a list of GUIs.
+
+[[read_oneline]]
+How to read `git log --oneline`'s output
+----------------------------------------
+
+In `git log`'s output, the latest commit is at the top.
+Here's an example of what the output might look like:
+
+----
+e9c0b17 (HEAD -> main) Update README.md
+2e018a5 Initial commit
+----
+
+Each line has 3 parts:
+
+1. The commit ID (like `e9c0b17`)
+2. Optional extra info (like `(HEAD -> main)`). Git calls this a "decoration".
+3. The commit message (like `Update README.md`)
+
+We're only going to talk about 2 kinds of decorations here:
+`(main)` and `(HEAD -> main)`. Here's how to read each of them:
+
+- `e9c0b17 (main)` means that `e9c0b17` is the latest commit on the `main` branch.
+- `e9c0b17 (HEAD -> main)` means that `e9c0b17` is the latest commit on
+ the `main` branch, AND that `main` is the current branch.
+
+[NOTE]
+`HEAD` is a special file in the `.git` directory where Git stores the
+name of your current branch. So you can read `HEAD -> main` as "current
+branch is main".
+
+Step 4: Make another commit
+---------------------------
+
+When you make a new commit, Git updates your current branch to point
+at that commit. Right now, `git log --oneline` looks like this, because
+we've made 2 commits:
+
+----
+e9c0b17 (HEAD -> main) Update README.md
+2e018a5 Initial commit
+----
+
+Now make a third commit, by editing `README.md` again, and running this command:
+
+----
+git commit -am "Another update to README.md"
+----
+
+Now run `git log --oneline` again to see how our branch looks now.
+
+----
+37634fd (HEAD -> main) Another update to README.md
+e9c0b17 Update README.md
+2e018a5 Initial commit
+----
+
+This shows us that the latest commit on the `main` branch is now
+"Another update to README.md".
+
+Step 5: Create a branch
+-----------------------
+
+Here's how to create a new branch and make a commit on it. We're going
+to create a branch called `add-fruits` that adds a list of fruits.
+
+First, create the branch and switch to it, by running this command:
+
+----
+git switch -c add-fruits
+----
+
+The `-c` flag stands for "create". You should see the output:
+
+----
+Switched to a new branch 'add-fruits'
+----
+
+Now, in your text editor, create a new file called `fruits.txt` with
+some fruits in it. Then add it and commit, like this:
+
+----
+git add fruits.txt
+git commit -m "Add fruit list"
+----
+
+Run `git log --oneline` again to get a list of all the commits on the
+current branch.
+
+----
+cd4bb48 (HEAD -> add-fruits) Add fruit list
+37634fd (main) Another update to README.md
+e9c0b17 Update README.md
+2e018a5 Initial commit
+----
+
+See <<read_oneline,How to read `git log --oneline`'s output>> above for
+an explanation of how to interpret this output.
+
+To summarize, this tells us that there's been 1 commit ("Add fruit list")
+since our `add-fruits` branch split off from the `main` branch.
+
+Step 6: Get a list of all branches
+----------------------------------
+
+You can get a list of all branches by running this command:
+
+----
+git branch
+----
+
+The output should look like this:
+
+----
+* add-fruits
+ main
+----
+
+This says that you have 2 branches (`main` and `add-fruits`). The one
+with the `*` next to it is the current branch.
+
+Step 7: Switch branches
+-----------------------
+
+Change your current branch to `main` by running:
+
+----
+git switch main
+----
+
+This command:
+
+1. Updates the files in your working directory to match the `main` branch.
+ For example, if `main` is at the commit `aa33bb`, then `git switch main`
+ will give you the files from the commit `aa33bb`.
+2. Sets your current branch to `main`, so that any new commits
+ you make will be on that branch
+
+
+Run `ls`. You should see that the new `fruits.txt` file you created is gone:
+
+-----
+$ git switch main
+$ ls
+README.md
+-----
+
+Of course, `fruits.txt` is not actually gone: it's stored in the `.git`
+directory and we can switch back to the `add-fruits` branch to get it
+back.
+
+Run `git switch add-fruits` to switch back to the `add-fruits`
+branch, and run `ls` again. The `fruits.txt` file should reappear:
+
+-----
+$ git switch add-fruits
+$ ls
+fruits.txt
+README.md
+-----
+
+Step 8: Create another branch
+-----------------------------
+
+Now create a second branch called `add-animals`. We're creating two
+branches to show what the process of working on multiple changes at the
+same time looks like.
+
+First, switch back to the `main` branch. This is important because
+normally when you start a new branch, you'll start it from the
+current `main`.
+
+We normally start from `main` because if you create a branch called `two`
+while on the `one` branch, merging `two` into `main` will also
+merge `one`. Starting from `main` keeps all the branches separate.
+
+-----
+git switch main
+-----
+
+Then create a branch called `add-animals`.
+
+-----
+git switch -c add-animals
+-----
+
+Now create a file named `animals.txt` with some animal names in it, add
+it, and commit it.
+
+-----
+git add animals.txt
+git commit -m "Add animal list"
+-----
+
+Step 9: Look at our branches and commits
+----------------------------------------
+
+In Git it's extremely useful to be able to visualize your branches.
+There are many GUIs built by the community which can do this, but in
+this tutorial we're going to use the command line because it's the only
+interface we can guarantee everyone reading the tutorial has.
+
+Run this command to show all branches and commits:
+
+-----
+git log --oneline --graph --all
+-----
+
+The output should look like this:
+
+-----
+* 1ceb7b4 (HEAD -> add-animals) Add animal list
+| * cd4bb48 (add-fruits) Add fruit list
+|/
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+How to read `git log --graph`'s output
+--------------------------------------
+
+`git log --oneline --graph --all` prints out a text-based visualization
+of all your Git branches and their history.
+
+This isn't the best visualization, but to use branches well you need
+some way to get this information, and it's the only visualization the
+command line Git interface has. Almost every Git GUI will have another
+visualization you can use.
+
+Here's some example output:
+
+-----
+* 1ceb7b4 (HEAD -> add-animals) Add animal list
+| * cd4bb48 (add-fruits) Add fruit list
+|/
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+How to read this:
+
+* Every `*` is a commit
+* As usual with `git log`, the latest commit is at the top
+* The `|` and `/` are ASCII art lines that Git uses to show
+ what the parents of a commit are. Here they're showing that `37634fd`
+ is the parent of both `cd4bb48` and `1ceb7b4`.
+
+See <<read_oneline,How to read `git log --oneline`'s output>> above for
+how to read the decorations like `(main)` or `(HEAD -> add-animals)`.
+
+Overall this shows that the `add-animals` and `add-fruits` branches have
+both added one new commit since they split off from the `main` branch.
+
+Step 10: Merge the `add-animals` branch into `main`
+---------------------------------------------------
+
+Now imagine that you're done with your work on the `add-animals` branch, and
+you're ready to bring that work onto your `main` branch.
+
+Right now `add-animals` is one commit "ahead" of the `main` branch.
+To bring all the work in `add-animals` into `main`, we can just move
+`main` forward to match the `add-animals` branch.
+
+This is the simplest possible situation when trying to bring the work
+from one branch into another branch, and Git calls it a **fast-forward
+merge**.
+
+Merge `add-animals` into the main branch by running these two commands:
+
+----
+git switch main
+git merge add-animals
+----
+
+The output should look like this:
+
+----
+Updating 37634fd..1ceb7b4
+Fast-forward
+ animals.txt | 1 +
+ 1 file changed, 1 insertion(+)
+ create mode 100644 animals.txt
+----
+
+The `Fast-forward` output means that this was a fast-forward merge.
+
+Step 11: Delete the `add-animals` branch
+----------------------------------------
+
+Now that you've integrated `add-animals` branch into `main`, you can
+safely delete it. Delete the branch by running this command. `-d` stands
+for "delete":
+
+-----
+git branch -d add-animals
+-----
+
+Running this is safe: it'll refuse to delete any branch that hasn't
+already been integrated into the current branch.
+
+It's useful to delete branches after they've been merged because it
+stops them from cluttering up your branch list (from `git branch`).
+
+Step 12: Look at our branches and commits again
+-----------------------------------------------
+
+Now that we've made some changes, run this command to show all branches
+and commits again:
+
+-----
+git log --oneline --graph --all
+-----
+
+The output should look like this:
+
+-----
+* cd4bb48 (add-fruits) Add fruit list
+| * 1ceb7b4 (HEAD -> main) Add animal list
+|/
+* 37634fd Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+Step 13: Merge the `add-fruits` branch into `main`
+--------------------------------------------------
+
+The output from the last step shows that we still have an `add-fruits`
+branch that's branched off a previous version of the `main` branch.
+
+In this situation where `main` and `add-fruits` both have new commits,
+we say that the two branches have "diverged". Having diverged branches
+is very common when working together on a team, because usually on a
+large team many people are making commits at the same time.
+
+If two branches have diverged, you still use the command `git merge`
+to combine them, but it does something different from our previous merge
+in Step 10.
+
+Now run `git merge` to see what happens:
+
+----
+git merge --no-edit add-fruits
+----
+
+The `--no-edit` option tells `git merge` to use the default commit
+message. Normally `git merge` will open a text editor to ask you to
+write a commit message, but we're skipping that step here.
+
+You should see the output:
+
+----
+Merge made by the 'ort' strategy.
+ fruits.txt | 1 +
+ 1 file changed, 1 insertion(+)
+ create mode 100644 fruits.txt
+----
+
+Once the branch is merged, delete it by running:
+
+----
+git branch -d add-fruits
+----
+
+To see what `git merge` did, run `git log --oneline --graph` again.
+
+----
+* e3c630d (HEAD -> main) Merge branch 'add-fruits'
+|\
+| * cd4bb48 Add fruit list
+* | 1ceb7b4 Add animal list
+|/
+* 37634fd Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+----
+
+Here you can see that it created a new commit `e3c630d`. This commit
+looks different from the other commits because it has two parents:
+cd4bb48 ("Add fruit list") and 1ceb7b4 ("Add animal list"). This kind
+of commit with two parents is called a "merge commit".
+
+Note: merge conflicts
+---------------------
+
+Git has an automatic merge algorithm to combine the code from two
+branches. In the example from Step 13, it's simple: one side added
+`fruits.txt` and the other side added `animals.txt`, so the merge adds
+both files.
+
+But if the two branches both edited the same lines of the same files,
+Git will ask you to decide how to handle it. This is called a "merge
+conflict".
+
+See linkgit:gitmergeconflicts[7] (`git help mergeconflicts`) for a
+guide to handling merge conflicts.
+
+3 ways to think about branches
+------------------------------
+
+In Git there are always 3 ways to think about a branch, and different
+commands will treat a branch in different ways. For example, let's look
+at the earlier setup again with the `add-fruits` branch. It has a `main`
+branch with 3 commits on it, and an `add-fruits` branch with one commit.
+
+-----
+ * cd4bb48 (add-fruits) Add fruit list
+ /
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+We can think of the `add-fruits` branch as:
+
+1. Just the 1 commit that "branched off" of the `main` branch (`cd4bb48`).
+2. The full history of the branch since the beginning of the repository,
+ including all the commits on `main` (4 commits in this case).
+ For example, `git log add-fruits` will show you the full history.
+3. Just the latest commit on that branch.
+ For example, `git show add-fruits` will show you the latest commit.
+
+How to use branches to collaborate: it depends
+----------------------------------------------
+
+There are lots of ways to use branches to collaborate with other people.
+We don't have space for a full guide to collaborating with Git here, but
+after a very quick introduction to `git pull`, we'll give examples of
+how each of our characters from the beginning might use branches.
+
+In these examples we're going to use `git push`, `git pull`, `git
+clone`, and `git remote add`. For a basic introduction to `git push` and
+`git remote add`, see Step 14 of linkgit:gittutorial[7].
+
+Using `git pull`: the basics
+----------------------------
+
+Here's the simplest way to use `git pull`.
+
+When you use `git clone` to clone a repository, it checks out a branch
+by default. The branch it checks out is usually the "main" branch.
+This is the one exception to "Git mostly doesn't treat the main branch
+in any special way". Technically the repository's owner can set the
+default branch to anything, but normally they'll set it to the main
+branch.
+
+-------
+git clone https://example.com/example.git
+-------
+
+After cloning a repository, you can run `git pull` while on the main
+branch to update it with the latest version, like this:
+
+-------
+git switch main
+git pull
+-------
+
+This is all you need to know about `git pull` to understand these
+examples.
+
+Example: Emilia the PhD student
+-------------------------------
+
+Emilia is writing her PhD thesis. She follows the steps from
+linkgit:gittutorial[7] to set up a Git repository on the Internet so
+that she can back up her work.
+
+To back up her work after making a commit, she runs:
+
+----
+git push origin main
+----
+
+Sometimes, she creates a branch to make an experimental change she's not
+sure that she's going to keep, like `rewrite-chapter-5`.
+
+She does this by running:
+
+----
+git switch -c rewrite-chapter-5
+----
+
+If she decides that the experimental change should be merged, she merges
+it into `main` like this:
+
+----
+git switch main
+git merge rewrite-chapter-5
+----
+
+Or if she decides the rewrite of chapter 5 was a bad idea, she can
+delete the branch:
+
+----
+git branch -D rewrite-chapter-5
+----
+
+Example: Abdul the open source contributor
+------------------------------------------
+
+Abdul is contributing to an open source project for the first time.
+
+First, he finds the official Git repository for the project and clones
+it, like this:
+
+----
+git clone https://example.com/project/project
+----
+
+He doesn't have permission to push changes directly to that
+project, so he creates his own copy of the repository at
+https://example.com/abdul/project.
+
+Then he adds that repository as a second remote, like this:
+
+----
+git remote add abdul https://example.com/abdul/project
+----
+
+Before starting work on his branch, he makes sure that he has the
+latest version of the `main` branch using `git pull`, like this:
+
+----
+git switch main
+git pull
+----
+
+Then he creates a new branch, like this:
+
+----
+git switch -c new-feature
+----
+
+Once he's done with his branch, he pushes the branch to his Git
+repository, like this:
+
+----
+git push abdul new-feature
+----
+
+Then he goes through the open source project's process to submit his
+branch for review.
+
+Example: Betsy the corporate employee
+-------------------------------------
+
+On her first day of work, she clones the company's Git repository by
+running:
+
+----
+git clone git@example.com:company/project
+----
+
+She has access to push new branches to this repository with her work,
+but their system doesn't allow pushing to the `main` branch directly.
+
+Before starting work on her new feature, she makes sure that she has the
+latest version of the `main` branch using `git pull`, like this:
+
+----
+git switch main
+git pull
+----
+
+Then she creates a new branch, like this:
+
+----
+git switch -c new-feature
+----
+
+Once she's done with her branch, she pushes the branch to the company
+Git repository, like this:
+
+----
+git push origin new-feature
+----
+
+Then she goes through her company's process for getting branches merged.
+
+Example: Daniela and Carmen with the cat shelter website
+--------------------------------------------------------
+
+Daniela and Carmen create a Git repository for their cat shelter website.
+
+They both clone it onto their computer like this:
+
+----
+git clone git@example.com:cat-shelter/kitties.git
+----
+
+They decide to work together by just pushing all of their commits to the
+`main` branch, without using any other branches.
+
+When Daniela wants to do work, she first runs `git pull` on the main
+branch, like this:
+
+----
+git pull
+----
+
+She also checks in with Carmen to make sure they won't be working on
+the same files. Then she works on her changes. Then, before pushing her
+changes, she runs this command to merge any changes Carmen has made.
+
+----
+git pull --no-rebase
+----
+
+We don't have space for a full introduction to linkgit:git-pull[1]
+here, but `git pull` fetches Carmen's changes and merges them into the
+current branch. The `--no-rebase` flag tells Git to use `git merge` to
+do the merge.
+
+Then she pushes her changes with:
+
+----
+git push
+----
+
+Tip: put your current branch in your shell prompt
+-------------------------------------------------
+
+Accidentally doing a Git operation on the wrong branch can be really
+annoying to undo. Because of this, it's extremely useful in Git to
+always know what your current branch is.
+
+To help with this, Git comes with a shell script called `git-prompt.sh`
+that has instructions for how to make sure your current Git branch is
+always in your shell prompt. If it's not already on your machine, you can
+find it in the https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh[official Git repository here].
+There are also many shell plugins to do this.
+
+For example, if you're on the `main` branch, this can make your shell
+prompt look like this:
+
+----
+[user@host myproject (main)]$
+----
+
+[[guis]]
+GUI tools
+---------
+
+Here are a few open source GUI tools. All of them work on Linux, Mac,
+and Windows unless otherwise mentioned:
+
+- `gitk` and `git gui` both come with Git. `git gui` focuses on making
+ commits and `gitk` visualizes the project's history.
+ See linkgit:gitk[1] and linkgit:git-gui[1] for more info, and
+ https://git-scm.com/install/ for install instructions.
+- TortoiseGit (https://tortoisegit.org/) for Windows
+- GitUp (https://gitup.co/) for Mac
+
+Interactive terminal UIs:
+
+- LazyGit (https://github.com/jesseduffield/lazygit)
+- tig (https://jonas.github.io/tig/)
+
+Many text editors have Git integrations, for example:
+
+- Magit (https://magit.vc/) for Emacs
+- Fugitive (https://github.com/tpope/vim-fugitive) for Vim
+- Many IDEs (VS Code, Eclipse, JetBrains, etc) have built-in Git
+ integrations. This can be a good option if you're already using one
+ of them.
+
+Where to learn more
+-------------------
+
+- When merging two branches, there can be a conflict if both sides
+ edited the same lines of a file. linkgit:gitmergeconflicts[7]
+ (or `git help mergeconflicts`) is a guide to handling merge conflicts.
+- The UPSTREAM BRANCHES section in linkgit:git-pull[1] explains how to
+ configure where `git push` or `git pull` will push or pull from.
+- Some teams prefer to use linkgit:git-rebase[1] and a fast-forward
+ merge to combine branches instead of using merge commits.
+- linkgit:gitdatamodel[7] explains how Git represents branches and
+ commits.
+
+GIT
+---
+Part of the linkgit:git[1] suite
diff --git a/Documentation/meson.build b/Documentation/meson.build
index b290557834..23634ebd7e 100644
--- a/Documentation/meson.build
+++ b/Documentation/meson.build
@@ -208,6 +208,7 @@ manpages = {
'gitrevisions.adoc' : 7,
'gitsubmodules.adoc' : 7,
'gittutorial-2.adoc' : 7,
+ 'gittutorial-branches.adoc' : 7,
'gittutorial.adoc' : 7,
'gitworkflows.adoc' : 7,
}
diff --git a/command-list.txt b/command-list.txt
index 56d0d7ed9b..0e3e3fc378 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -245,6 +245,7 @@ gitrepository-layout userinterfaces
gitrevisions userinterfaces
gitsubmodules guide
gittutorial guide
+gittutorial-branches guide
gitweb ancillaryinterrogators
gitworkflows guide
scalar mainporcelain
base-commit: 3c60ef1e38ee80337025a1b908327f7879386329
--
gitgitgadget
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-09 21:33 [PATCH] doc: add tutorial on branches for beginners Julia Evans via GitGitGadget
@ 2026-11-09 21:56 ` Junio C Hamano
2026-11-09 22:01 ` Julia Evans
2026-11-18 12:43 ` Julia Evans
` (3 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2026-11-09 21:56 UTC (permalink / raw)
To: Julia Evans via GitGitGadget
Cc: git, Patrick Steinhardt, D. Ben Knoble, Julia Evans
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Julia Evans <julia@jvns.ca>
>
> Because Git's branches are so flexible and the meaning of a branch is
> only what people assign to it, it's important to talk about some of the
> social context about branches. Do this in two ways:
A meta-comment, not limited to this patch.
We are currently reviewer-bandwidth-limited. Having many topics
in-flight under review would not help these topics go any faster
with greater parallelism. In fact, it slows everything down by
wearing available reviewers down due to forced context switching.
I wonder what incentives, carrots and sticks we have on those who
have in-flight topics that are so close to the finish line to
concentrate on completing these topics before sending new ones.
Ideas?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-09 21:56 ` Junio C Hamano
@ 2026-11-09 22:01 ` Julia Evans
2026-11-09 22:11 ` Junio C Hamano
0 siblings, 1 reply; 15+ messages in thread
From: Julia Evans @ 2026-11-09 22:01 UTC (permalink / raw)
To: Junio C Hamano, Julia Evans; +Cc: git, Patrick Steinhardt, D. Ben Knoble
> I wonder what incentives, carrots and sticks we have on those who
> have in-flight topics that are so close to the finish line to
> concentrate on completing these topics before sending new ones.
>
> Ideas?
For sure, I can avoid submitting new topics in the future until the
current ones are finished. I don't have any other changes in progress
in any case.
I'm very conscious that reviewer bandwidth is limited and I'm very
interested in ideas for how to make the docs review process easier.
- Julia
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-09 22:01 ` Julia Evans
@ 2026-11-09 22:11 ` Junio C Hamano
2026-11-10 14:31 ` Julia Evans
0 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2026-11-09 22:11 UTC (permalink / raw)
To: Julia Evans; +Cc: Julia Evans, git, Patrick Steinhardt, D. Ben Knoble
"Julia Evans" <julia@jvns.ca> writes:
>> I wonder what incentives, carrots and sticks we have on those who
>> have in-flight topics that are so close to the finish line to
>> concentrate on completing these topics before sending new ones.
>>
>> Ideas?
>
> For sure, I can avoid submitting new topics in the future until the
> current ones are finished. I don't have any other changes in progress
> in any case.
>
> I'm very conscious that reviewer bandwidth is limited and I'm very
> interested in ideas for how to make the docs review process easier.
My interest in making review process better is not limited to
documentation patches, though.
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-09 22:11 ` Junio C Hamano
@ 2026-11-10 14:31 ` Julia Evans
0 siblings, 0 replies; 15+ messages in thread
From: Julia Evans @ 2026-11-10 14:31 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Julia Evans, git, Patrick Steinhardt, D. Ben Knoble
On Mon, Nov 9, 2026, at 5:11 PM, Junio C Hamano wrote:
> "Julia Evans" <julia@jvns.ca> writes:
>
>>> I wonder what incentives, carrots and sticks we have on those who
>>> have in-flight topics that are so close to the finish line to
>>> concentrate on completing these topics before sending new ones.
>>>
>>> Ideas?
>>
>> For sure, I can avoid submitting new topics in the future until the
>> current ones are finished. I don't have any other changes in progress
>> in any case.
>>
>> I'm very conscious that reviewer bandwidth is limited and I'm very
>> interested in ideas for how to make the docs review process easier.
>
> My interest in making review process better is not limited to
> documentation patches, though.
When I applied for funding from the Sovereign Tech Agency to work on
the Git project's documentation, the main risk I flagged in my application
was that reviewer capacity in the project is very limited. I tried to deal with
this in a several ways:
1. I emailed a few people who had reviewed my patches in the past to ask
if they would be have capacity to do review on the new patches.
Patrick and Ben agreed to do some reviews which I really appreciate.
2. I applied for a relatively small amount of funding, which limits how
many hours Marie and I actually spent writing. Fewer hours spent writing
means less work to review :)
3. We recruited dozens of test readers to participate in a kind of side
review process. That doesn't serve the same function as the mailing list
review of course, but it hugely improves the final quality of the document
without introducing extra pressure on Git project's reviewers.
I don't know which of these strategies would apply to code changes but
those are some of things I've tried so far.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-09 21:33 [PATCH] doc: add tutorial on branches for beginners Julia Evans via GitGitGadget
2026-11-09 21:56 ` Junio C Hamano
@ 2026-11-18 12:43 ` Julia Evans
2026-11-23 18:05 ` D. Ben Knoble
2026-11-23 18:05 ` D. Ben Knoble
` (2 subsequent siblings)
4 siblings, 1 reply; 15+ messages in thread
From: Julia Evans @ 2026-11-18 12:43 UTC (permalink / raw)
To: Julia Evans via GitGitGadget, git; +Cc: Patrick Steinhardt, D. Ben Knoble
This tutorial is a bit of a long read, so here are some of my own notes
on the branch after a week away from it. Also let me know if I can do
anything else to help review this one! My current funding ends Nov. 30,
though I'll see this one through without funding if needed.
1. It was a bit tougher to get test readers for this one even though so
many people said they were interested in learning about branches and
collaboration, and I'm not sure why. Almost everyone who completed it
said that it took less than an hour. Maybe a table of contents would
help folks understand the overall structure to see what they're getting
into?
2. This document is doing a pretty tricky dance where we're introducing
some example Git workflows for collaboration without explaining remotes
or upstreams, because the tutorial is already quite long, but
ultimately the reason many people use Git is to collaborate and it feels
silly to not talk about collaboration at all. I believe we gave at least
a basic explanation of everything that is actually used in the example
Git workflows but this will definitely leave some people with questions
about how remotes work. We don't have a great place to point people to
learn more about remotes. In the future it might make sense to write
another guide on remotes and upstreams (maybe `git help remotes`?).
3. One of the test readers commented that they were confused by `git
switch` because they're familiar with `git checkout`. At first I didn't
get it (if someone already knows about `git checkout`, why do they even
need to read this tutorial?), but actually some of the test readers had
been using Git for quite a long time (even 10+ years) but were still
interested in a basic tutorial on branches because they still weren't
clear on the basics of how branches work. So it might be better to also
mention `git checkout`.
4. Only using `git log --graph` for the branch diagrams is tough and a
lot of people hard a hard time understanding the ASCII art diagrams. I
didn't see a better option because other ASCII diagrams are not really
that much better IMO (you still have to explain them, and they don't
have the benefit of being a tool you can actually use to explore your
repo). And we don't have prior art for using SVGs in the HTML docs.
- Julia
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-09 21:33 [PATCH] doc: add tutorial on branches for beginners Julia Evans via GitGitGadget
2026-11-09 21:56 ` Junio C Hamano
2026-11-18 12:43 ` Julia Evans
@ 2026-11-23 18:05 ` D. Ben Knoble
2026-11-24 15:56 ` Julia Evans
2026-11-24 17:16 ` Junio C Hamano
2026-11-24 21:13 ` [PATCH v2] " Julia Evans via GitGitGadget
4 siblings, 1 reply; 15+ messages in thread
From: D. Ben Knoble @ 2026-11-23 18:05 UTC (permalink / raw)
To: Julia Evans via GitGitGadget; +Cc: git, Patrick Steinhardt, Julia Evans
Hi Julia, sorry for the delay! I've read the current email thread, so
I'm replying with a bit of "foreknowledge" ;)
On Mon, Nov 9, 2026 at 4:33 PM Julia Evans via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Julia Evans <julia@jvns.ca>
>
> Because Git's branches are so flexible and the meaning of a branch is
> only what people assign to it, it's important to talk about some of the
> social context about branches. Do this in two ways:
>
> 1. Introduce some imaginary characters who are learning branches for the
> first time and examples of workflows they might use. Test readers
> said this was helpful because it helped them see different ways
> they might use branches.
This is extremely helpful, not least because of what it does for this doc, but
because it sets up future guides to refer back to well-known scenarios. In
particular, I'm mulling on a triangular workflow guide, which could feasibly be
one component of a guide to collaboration with remotes; these characters will
have different things to say about remotes!
> On `git log`:
>
> - Use the output of `git log --graph` to visualize branches instead of
> a more abstract ASCII diagram, since it serves a double purpose of
> teaching people how to read `git log`'s output.
> But also mention that folks may prefer to use a GUI to visualize
> branches.
> - Include two sections to explain the output of `git log`, since several
> test readers found it very hard to understand. In that explanation,
> only explain `HEAD` fairly briefly and instead keep the focus on the
> idea of a "current branch", since that's the term Git's UI normally
> uses.
Much appreciated. Another thing I've been doing at work is showing folks how to
find a "map", as it were: my recipe for getting folks unstuck with Git is to
1. Find out where you are
2. Decide where you want to go
3. Discover how to get there
and git-log is crucial for step (1).
> On the conceptual introduction at the beginning:
>
> - One of the biggest issues with explaining branches is that there are 3
> ways in Git to think of branches and it's not straightforward to
> explain how to reconcile them:
> 1. just the commits that "branch off"
> 2. the latest commit on the branch
> 3. the full history since the beginning of time
> Handle this by starting with the "tree" metaphor where branches
> "branch off" a central trunk (way 1), since this makes sense with how
> people actually want to use branches. Point out some issues with the
> tree metaphor and talk about how it relates to the way Git represents
> branches (way 2).
> - Avoid using computer science jargon, because it's a major barrier to
> folks without a CS background. It's not useful or realistic to teach
> most beginners the term "directed acyclic graph" just so they can
> learn branches. Mention the term "directed acyclic graph" briefly in a
> note for folks who are already familiar with that term and link folks
> to the data model if they'd like more information.
> - Include some basic facts about commits. Folks seemed to find this
> helpful, one person said they didn't realize it would be so hard to
> change their email address later.
>
> To keep it readable:
> - Don't assume that the reader has read `gittutorial`, and instead
> refer back to it explicitly if it's relevant.
> - Always include the output for every command. Test readers said
> this was helpful.
>
> Other choices about material that is/isn't included:
>
> - `git-prompt.sh` (yes): Mention how important it is to be aware
> what branch you're on, and suggest using `git-prompt.sh`. Link to
> git-prompt.sh on GitHub since several test readers couldn't find it on
> their machine. The test readers liked this.
> - fast-forward merges (yes): Explain the difference between a fast-forward
> merge and a merge commit by giving examples of what each one looks
> like.
> - upstreams/rebase (no): Don't explain what an upstream is or introduce
> rebase, since we're already introducing a lot of concepts. Instead
> include a "Where to learn more" section with some pointers to where to
> continue learning.
> - GUIs (yes): Some readers wanted a suggestion for what GUI to use. It's
> very hard to suggest an appropriate GUI because there are so many and
> so many of them are not open source, but give a couple of suggestions
> of open source tools that seem to be popular with the community. Also
> mention that many non-open-source IDEs have built-in Git integrations
> for folks who are already using those tools who might not be aware,
> since they're a popular way to use Git.
All quite sensible to me.
> +Step 8: Create another branch
> +-----------------------------
> +
> +Now create a second branch called `add-animals`. We're creating two
> +branches to show what the process of working on multiple changes at the
> +same time looks like.
> +
> +First, switch back to the `main` branch. This is important because
> +normally when you start a new branch, you'll start it from the
> +current `main`.
> +
> +We normally start from `main` because if you create a branch called `two`
> +while on the `one` branch, merging `two` into `main` will also
> +merge `one`. Starting from `main` keeps all the branches separate.
This feels a bit confusing to me on first read, if only because the "two" and
"one" branches are hypothetical (and because we haven't covered merges yet).
I don't love to keep the reader in suspense ("we'll explain why we do this
later"), but I do wonder if we can give a better demonstration of what happens
when we stack a branch like this by using the example names here?
Perhaps we can start with the idea that we want to keep work independent
("Branches are a tool to organize your work", "working on multiple unrelated
changes"), and then after merges are introduced we can revisit the stacked
version and show what happens in that scenario? There are pros and cons to
stacking, but I think covering "branch per independent idea" as the norm is a
good way to handle it.
(I've used "stack" here because that's what the industry is starting to call
such things, though even then such a stack is usually held together by a set of
related ideas. This example is independent enough that I would probably tell the
author to split up the branches if they were stacked!)
> +Step 13: Merge the `add-fruits` branch into `main`
> +--------------------------------------------------
> +Here you can see that it created a new commit `e3c630d`. This commit
> +looks different from the other commits because it has two parents:
> +cd4bb48 ("Add fruit list") and 1ceb7b4 ("Add animal list"). This kind
> +of commit with two parents is called a "merge commit".
> +Note: merge conflicts
> +---------------------
> +See linkgit:gitmergeconflicts[7] (`git help mergeconflicts`) for a
> +guide to handling merge conflicts.
> +3 ways to think about branches
> +------------------------------
> +How to use branches to collaborate: it depends
> +----------------------------------------------
> +Using `git pull`: the basics
> +----------------------------
> +Example: Emilia the PhD student
> +-------------------------------
> +Tip: put your current branch in your shell prompt
> +-------------------------------------------------
> +[[guis]]
> +GUI tools
> +---------
> +Where to learn more
> +-------------------
Here are the last handful of sections, and 2 paragraphs that come between what I
see as major sections. Here alas flat text bites us a bit: it's not particularly
evident that step 13 + it's merge conflict note form "the end" of the practicum,
and the stuff afterwards is (somewhat) back to the introductory concept idea or
examples.
I don't have a particular way in mind to alleviate this, but some ideas:
• Transition paragraphs? ("This concludes the tutorial on XYZ; next, we'll
cover a few more branching concepts")
• Perhaps the Examples ought to come earlier, but I'm not sure: we want both the
branching material and the collaboration aspect for some. Maybe we could move
the solo project earlier, and return to it to mention the backups/pushes after
the later bits about push?
All in all, I'm quite excited to see this be available to folks.
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-18 12:43 ` Julia Evans
@ 2026-11-23 18:05 ` D. Ben Knoble
0 siblings, 0 replies; 15+ messages in thread
From: D. Ben Knoble @ 2026-11-23 18:05 UTC (permalink / raw)
To: Julia Evans; +Cc: Julia Evans via GitGitGadget, git, Patrick Steinhardt
On Wed, Nov 18, 2026 at 7:43 AM Julia Evans <julia@jvns.ca> wrote:
>
> 1. It was a bit tougher to get test readers for this one even though so
> many people said they were interested in learning about branches and
> collaboration, and I'm not sure why. Almost everyone who completed it
> said that it took less than an hour. Maybe a table of contents would
> help folks understand the overall structure to see what they're getting
> into?
It certainly might! I also wondered how many of your test readers were
genuinely new to the ideas here, which can make it harder to get
readers.
> 2. This document is doing a pretty tricky dance where we're introducing
> some example Git workflows for collaboration without explaining remotes
> or upstreams, because the tutorial is already quite long, but
> ultimately the reason many people use Git is to collaborate and it feels
> silly to not talk about collaboration at all. I believe we gave at least
> a basic explanation of everything that is actually used in the example
> Git workflows but this will definitely leave some people with questions
> about how remotes work. We don't have a great place to point people to
> learn more about remotes. In the future it might make sense to write
> another guide on remotes and upstreams (maybe `git help remotes`?).
Yep, agreed. I've mulled on this a bit and will keep doing so---I have
some paternity leave coming up, so perhaps I'll find some time to
write in earnest. Mind doing some early feedback when I get there?
> 3. One of the test readers commented that they were confused by `git
> switch` because they're familiar with `git checkout`.
> So it might be better to also
> mention `git checkout`.
I waffle on this. It's probably easy to mention "switch is the modern
form, but you may see older guides teaching checkout" or something?
Any more than a sentence feels like another distraction, though, and
I'm also perfectly content to *not* mention checkout at all (and leave
that to folks to discover if they choose to).
> 4. Only using `git log --graph` for the branch diagrams is tough and a
> lot of people hard a hard time understanding the ASCII art diagrams.
Yeah, this is fair. "git show-branch" is probably harder to learn,
though presents similar information when it comes to "what's going on
with branches." I only mention it as a way to have *more* branch
diagrams :P
Anyway, I think my overall feeling is we want folks to learn how to
read log output (graph or not)---it's an important skill to working
with Git IMO. (What if there's no graphical environment available?) I
like how your approach sort of sneaks in the vegetables, too, and
future guides can build on that so folks get more exposure to and
build more confidence with the output.
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-23 18:05 ` D. Ben Knoble
@ 2026-11-24 15:56 ` Julia Evans
2026-11-24 19:04 ` Ben Knoble
0 siblings, 1 reply; 15+ messages in thread
From: Julia Evans @ 2026-11-24 15:56 UTC (permalink / raw)
To: D. Ben Knoble, Julia Evans via GitGitGadget; +Cc: git, Patrick Steinhardt
>> 1. Introduce some imaginary characters who are learning branches for the
>> first time and examples of workflows they might use. Test readers
>> said this was helpful because it helped them see different ways
>> they might use branches.
> This is extremely helpful, not least because of what it does for this doc, but
> because it sets up future guides to refer back to well-known scenarios. In
> particular, I'm mulling on a triangular workflow guide, which could feasibly be
> one component of a guide to collaboration with remotes; these characters will
> have different things to say about remotes!
Cool! I think probably we'd want to re-introduce the characters each
time (and maybe even choose different characters depending on the
situation). For a more advanced workflow the characters might be different.
>> +Step 8: Create another branch
>> +-----------------------------
>> +
>> +Now create a second branch called `add-animals`. We're creating two
>> +branches to show what the process of working on multiple changes at the
>> +same time looks like.
>> +
>> +First, switch back to the `main` branch. This is important because
>> +normally when you start a new branch, you'll start it from the
>> +current `main`.
>> +
>> +We normally start from `main` because if you create a branch called `two`
>> +while on the `one` branch, merging `two` into `main` will also
>> +merge `one`. Starting from `main` keeps all the branches separate.
> This feels a bit confusing to me on first read, if only because the "two" and
> "one" branches are hypothetical (and because we haven't covered merges yet).
> I don't love to keep the reader in suspense ("we'll explain why we do this
> later"), but I do wonder if we can give a better demonstration of what happens
> when we stack a branch like this by using the example names here?
>
> Perhaps we can start with the idea that we want to keep work independent
> ("Branches are a tool to organize your work", "working on multiple unrelated
> changes"), and then after merges are introduced we can revisit the stacked
> version and show what happens in that scenario? There are pros and cons to
> stacking, but I think covering "branch per independent idea" as the norm is a
> good way to handle it.
I like this, I'll try just saying "You'll usually want to start all new
branches from the `main` branch
to keep your branches independent from each other."
I agree it's weird to talk about merging since we haven't introduced it
yet. I'll take that out.
I think stacking is probably too advanced for this beginner tutorial.
>> ...
> Here are the last handful of sections, and 2 paragraphs that come between what I
> see as major sections. Here alas flat text bites us a bit: it's not particularly
> evident that step 13 + it's merge conflict note form "the end" of the practicum,
> and the stuff afterwards is (somewhat) back to the introductory concept idea or
> examples.
I agree the last few sections are pretty messy, thanks for finding that.
I've reorganized things for v2 like this::
- Move the "merge conflicts" section into a note
- Move the "3 ways to think about branch" inline in the step-by-step
tutorial, after step 6 (next to the example it's talking about)
- Rename the section about workflows to "Examples of using branches to
collaborate" to make it clear that the `git pull` section is a
subsection of the overall workflows section
- Add a little overview at the beginning explaining the structure of the
document:
This tutorial contains:
1. <<intro,An introduction to branches>>
2. <<tutorial,A step-by-step practical tutorial>>
3. <<workflows,Example collaboration workflows>>
4. <<tip,Tips, GUI tools, and where to learn more>>
"Tips, GUI tools, and where to learn more" is still a little bit of a
grab bag at the end but at least it's laid out at the beginning now
Thanks for the review!
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-09 21:33 [PATCH] doc: add tutorial on branches for beginners Julia Evans via GitGitGadget
` (2 preceding siblings ...)
2026-11-23 18:05 ` D. Ben Knoble
@ 2026-11-24 17:16 ` Junio C Hamano
2026-11-24 21:13 ` [PATCH v2] " Julia Evans via GitGitGadget
4 siblings, 0 replies; 15+ messages in thread
From: Junio C Hamano @ 2026-11-24 17:16 UTC (permalink / raw)
To: Julia Evans via GitGitGadget
Cc: git, Patrick Steinhardt, D. Ben Knoble, Julia Evans
"Julia Evans via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Julia Evans <julia@jvns.ca>
> ...
> +Next, edit README.md and make another commit, like this:
> +
> +----
> +git commit -am "Update README.md"
> +----
> +
> +`git commit -am` commits the current version of all files that Git is
> +tracking.
> +
> +Now we're set up and we can start creating branches.
> +
> +Step 2: Find your current branch
> +--------------------------------
> +
> +In Git, you normally have a "current branch". You can see your current
> +branch by running `git status`. It's usually on the first line, like this:
> +
> +----
> +$ git status
> +
> +On branch main
> +----
After reading through the steps, the abrupt appearance of the "$" prompt
feels a bit disorienting. You have a good reason to use a prompt here,
to make it possible to tell what you type and what the commands tell you
apart. Wouldn't it be better to use the prompt consistently, e.g.,
making the last example of the previous step
----
$ git commit -a -m "Update README.md"
----
instead?
Side note. Yesterday I learned while reviewing an unrelated
patch that we encourage users not to squish short options
together into a single word, so I split your "-am <msg>" in the
above rewrite of the example.
There are a handful of other places where you add the "$" prompt in a
block that has both input and output, and many blocks that lack the "$"
prompt. The mixture looks rather messy.
> +Example: Emilia the PhD student
> +-------------------------------
> +
> +Emilia is writing her PhD thesis. She follows the steps from
> +linkgit:gittutorial[7] to set up a Git repository on the Internet so
> +that she can back up her work.
> +
> +To back up her work after making a commit, she runs:
> +
> +----
> +git push origin main
> +----
> +
> +Sometimes, she creates a branch to make an experimental change she's not
> +sure that she's going to keep, like `rewrite-chapter-5`.
> +
> +She does this by running:
> +
> +----
> +git switch -c rewrite-chapter-5
> +----
Would it help to explicitly mention that after running 'switch -c'
to create the branch, Emilia actually does some work on it before
the "If she decides to keep/If she decides to discard" paragraphs?
> +
> +If she decides that the experimental change should be merged, she merges
> +it into `main` like this:
> +
> +----
> +git switch main
> +git merge rewrite-chapter-5
> +----
> +
> +Or if she decides the rewrite of chapter 5 was a bad idea, she can
> +delete the branch:
> +
> +----
> +git branch -D rewrite-chapter-5
> +----
This is slightly misleading after saying "Or if she decides", which
implies that the previous one did not happen. If she did not switch
to 'main' and merge, she would still be on the rewrite-chapter-5
branch, and the "branch -D", even with a capital "-D", would fail.
Perhaps make the example switch back to 'main' before discarding the
branch?
> +Example: Daniela and Carmen with the cat shelter website
> +--------------------------------------------------------
> +
> +Daniela and Carmen create a Git repository for their cat shelter website.
A very minor thing, but wouldn't breaking the alphabetical order of
appearance of the characters be a bit jarring to readers? Does this
example need to be about Daniela and Carmen, not Carmen and Daniela?
> +They both clone it onto their computer like this:
> +
> +----
> +git clone git@example.com:cat-shelter/kitties.git
> +----
> +
> +They decide to work together by just pushing all of their commits to the
> +`main` branch, without using any other branches.
> +
> +When Daniela wants to do work, she first runs `git pull` on the main
> +branch, like this:
> +
> +----
> +git pull
> +----
> +
> +She also checks in with Carmen to make sure they won't be working on
> +the same files. Then she works on her changes. Then, before pushing her
> +changes, she runs this command to merge any changes Carmen has made.
Wouldn't it be helpful to be more explicit that before running this
command (git pull), she commits all her work? We assume that "pull"
somehow finishes cleanly, so ...
> +----
> +git pull --no-rebase
> +----
> +
> +We don't have space for a full introduction to linkgit:git-pull[1]
> +here, but `git pull` fetches Carmen's changes and merges them into the
> +current branch. The `--no-rebase` flag tells Git to use `git merge` to
> +do the merge.
> +
> +Then she pushes her changes with:
> +
> +----
> +git push
> +----
... there is no extra need for "git commit" before the "git push" that
comes after the "git pull --no-rebase".
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] doc: add tutorial on branches for beginners
2026-11-24 15:56 ` Julia Evans
@ 2026-11-24 19:04 ` Ben Knoble
0 siblings, 0 replies; 15+ messages in thread
From: Ben Knoble @ 2026-11-24 19:04 UTC (permalink / raw)
To: Julia Evans; +Cc: Julia Evans via GitGitGadget, git, Patrick Steinhardt
> Le 24 nov. 2026 à 10:56, Julia Evans <julia@jvns.ca> a écrit :
>
>
>>
>>> 1. Introduce some imaginary characters who are learning branches for the
>>> first time and examples of workflows they might use. Test readers
>>> said this was helpful because it helped them see different ways
>>> they might use branches.
>> This is extremely helpful, not least because of what it does for this doc, but
>> because it sets up future guides to refer back to well-known scenarios. In
>> particular, I'm mulling on a triangular workflow guide, which could feasibly be
>> one component of a guide to collaboration with remotes; these characters will
>> have different things to say about remotes!
>
> Cool! I think probably we'd want to re-introduce the characters each time (and maybe even choose different characters depending on the situation). For a more advanced workflow the characters might be different.
>
>>> +Step 8: Create another branch
>>> +-----------------------------
>>> +
>>> +Now create a second branch called `add-animals`. We're creating two
>>> +branches to show what the process of working on multiple changes at the
>>> +same time looks like.
>>> +
>>> +First, switch back to the `main` branch. This is important because
>>> +normally when you start a new branch, you'll start it from the
>>> +current `main`.
>>> +
>>> +We normally start from `main` because if you create a branch called `two`
>>> +while on the `one` branch, merging `two` into `main` will also
>>> +merge `one`. Starting from `main` keeps all the branches separate.
>> This feels a bit confusing to me on first read, if only because the "two" and
>> "one" branches are hypothetical (and because we haven't covered merges yet).
>> I don't love to keep the reader in suspense ("we'll explain why we do this
>> later"), but I do wonder if we can give a better demonstration of what happens
>> when we stack a branch like this by using the example names here?
>>
>> Perhaps we can start with the idea that we want to keep work independent
>> ("Branches are a tool to organize your work", "working on multiple unrelated
>> changes"), and then after merges are introduced we can revisit the stacked
>> version and show what happens in that scenario? There are pros and cons to
>> stacking, but I think covering "branch per independent idea" as the norm is a
>> good way to handle it.
>
> I like this, I'll try just saying "You'll usually want to start all new branches from the `main` branch
> to keep your branches independent from each other."
>
> I agree it's weird to talk about merging since we haven't introduced it yet. I'll take that out.
>
> I think stacking is probably too advanced for this beginner tutorial.
>
>>> ...
>> Here are the last handful of sections, and 2 paragraphs that come between what I
>> see as major sections. Here alas flat text bites us a bit: it's not particularly
>> evident that step 13 + it's merge conflict note form "the end" of the practicum,
>> and the stuff afterwards is (somewhat) back to the introductory concept idea or
>> examples.
>
> I agree the last few sections are pretty messy, thanks for finding that.
>
> I've reorganized things for v2 like this::
>
> - Move the "merge conflicts" section into a note
> - Move the "3 ways to think about branch" inline in the step-by-step tutorial, after step 6 (next to the example it's talking about)
> - Rename the section about workflows to "Examples of using branches to collaborate" to make it clear that the `git pull` section is a subsection of the overall workflows section
> - Add a little overview at the beginning explaining the structure of the document:
>
> This tutorial contains:
>
> 1. <<intro,An introduction to branches>>
> 2. <<tutorial,A step-by-step practical tutorial>>
> 3. <<workflows,Example collaboration workflows>>
> 4. <<tip,Tips, GUI tools, and where to learn more>>
>
> "Tips, GUI tools, and where to learn more" is still a little bit of a grab bag at the end but at least it's laid out at the beginning now
>
> Thanks for the review!
All sounds great to me :)
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2] doc: add tutorial on branches for beginners
2026-11-09 21:33 [PATCH] doc: add tutorial on branches for beginners Julia Evans via GitGitGadget
` (3 preceding siblings ...)
2026-11-24 17:16 ` Junio C Hamano
@ 2026-11-24 21:13 ` Julia Evans via GitGitGadget
2026-11-30 15:09 ` D. Ben Knoble
4 siblings, 1 reply; 15+ messages in thread
From: Julia Evans via GitGitGadget @ 2026-11-24 21:13 UTC (permalink / raw)
To: git; +Cc: D. Ben Knoble, Patrick Steinhardt, Julia Evans, Julia Evans
From: Julia Evans <julia@jvns.ca>
Because Git's branches are so flexible and the meaning of a branch is
only what people assign to it, it's important to talk about some of the
social context about branches. Do this in two ways:
1. Introduce some imaginary characters who are learning branches for the
first time and examples of workflows they might use. Test readers
said this was helpful because it helped them see different ways
they might use branches.
2. Explain the importance of a "main" or "master" branch in many
projects, and give a few examples of how projects might use it.
On `git log`:
- Use the output of `git log --graph` to visualize branches instead of
a more abstract ASCII diagram, since it serves a double purpose of
teaching people how to read `git log`'s output.
But also mention that folks may prefer to use a GUI to visualize
branches.
- Include two sections to explain the output of `git log`, since several
test readers found it very hard to understand. In that explanation,
only explain `HEAD` fairly briefly and instead keep the focus on the
idea of a "current branch", since that's the term Git's UI normally
uses.
On the conceptual introduction at the beginning:
- One of the biggest issues with explaining branches is that there are 3
ways in Git to think of branches and it's not straightforward to
explain how to reconcile them:
1. just the commits that "branch off"
2. the latest commit on the branch
3. the full history since the beginning of time
Handle this by starting with the "tree" metaphor where branches
"branch off" a central trunk (way 1), since this makes sense with how
people actually want to use branches. Point out some issues with the
tree metaphor and talk about how it relates to the way Git represents
branches (way 2).
- Avoid using computer science jargon, because it's a major barrier to
folks without a CS background. It's not useful or realistic to teach
most beginners the term "directed acyclic graph" just so they can
learn branches. Mention the term "directed acyclic graph" briefly in a
note for folks who are already familiar with that term and link folks
to the data model if they'd like more information.
- Include some basic facts about commits. Folks seemed to find this
helpful, one person said they didn't realize it would be so hard to
change their email address later.
To keep it readable:
- Don't assume that the reader has read `gittutorial`, and instead
refer back to it explicitly if it's relevant.
- Always include the output for every command. Test readers said
this was helpful.
Other choices about material that is/isn't included:
- `git-prompt.sh` (yes): Mention how important it is to be aware
what branch you're on, and suggest using `git-prompt.sh`. Link to
git-prompt.sh on GitHub since several test readers couldn't find it on
their machine. The test readers liked this.
- fast-forward merges (yes): Explain the difference between a fast-forward
merge and a merge commit by giving examples of what each one looks
like.
- upstreams/rebase (no): Don't explain what an upstream is or introduce
rebase, since we're already introducing a lot of concepts. Instead
include a "Where to learn more" section with some pointers to where to
continue learning.
- GUIs (yes): Some readers wanted a suggestion for what GUI to use. It's
very hard to suggest an appropriate GUI because there are so many and
so many of them are not open source, but give a couple of suggestions
of open source tools that seem to be popular with the community. Also
mention that many non-open-source IDEs have built-in Git integrations
for folks who are already using those tools who might not be aware,
since they're a popular way to use Git.
Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
Signed-off-by: Julia Evans <julia@jvns.ca>
---
doc: add tutorial on branches for beginners
This was reviewed by 17 test readers who overall said it helped them
understand branches. We addressed the feedback from the test readers to
improve it before submitting it here.
I think it would be good to add a little table of contents to
gittutorial.adoc to match this one's TOC as well. I'm not sure what the
best way to do that is since my understanding is that rebasing on the
latest master causes problems.
Changes in v2:
* Use a $ for the commands for consistency (thanks to Junio)
* Add more details in the example workflows to make sure they make
sense logically (thanks to Junio)
* Make sure the characters are alphabetized in the section order and in
sentences. Rename Emilia -> Anita, Abdul -> Bruno, Betsy -> Carmen,
Carmen and Daniela -> Daniela and Emilia. Keep the genders the same
so we don't have to change all the pronouns. (thanks to Junio)
* Deal with the poorly structured sections that Ben pointed at the end
as follows:
* Add a summary at the beginning to explain the overall structure
* Move "3 ways to think about a branch" to the middle, right after
creating the branch we're using as an example
* Move the merge conflicts section to a note at the end of Step 13
* Rename some of the headings to more clearly explain the structure
(around "the step by step tutorial" and "Examples of using branches
to collaborate")
* Delete the "We normally start from main because if you create a
branch called two..." explanation and instead just say that we want
to keep branches independent (thanks to Ben)
* One test reader said that in "3 ways to think about a branch", it was
confusing to them than #1 and #3 were the same (just one commit). Add
an extra commit to the add-fruits branch so that the branch has 2
commits, to make it more clear what a branch with multiple commits on
it looks like.
Note: I used this script
https://gist.github.com/jvns/bcd36fdd42952b9ec9a67ec139dba13e to create
the example repository used in this document and to copy and paste the
example output from. Not sure if we should store the contents of that
script somewhere: it's very annoying to update the examples without it.
I also realized there's an issue with that script where, because it
hardcodes GIT_COMMITTER_DATE, all the commits happen at the same time,
which makes the order of git log a bit weird. I manually adjusted Step
12 to account for that.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2307%2Fjvns%2Ftutorial-branches-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2307/jvns/tutorial-branches-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2307
Range-diff vs v1:
1: 5eaecda843 ! 1: d6824feca4 doc: add tutorial on branches for beginners
@@ Documentation/gittutorial-branches.adoc (new)
+- Part 1 (linkgit:gittutorial[7]): Introduction to commits and `git push`
+- Part 2 (you are here): Introduction to branches
+
++This tutorial contains:
++
++1. <<intro,An introduction to branches>>
++2. <<tutorial,A step-by-step practical tutorial>>
++3. <<workflows,Example collaboration workflows>>
++4. <<tip,Tips, GUI tools, and where to learn more>>
++
++
+Meet some example Git users
+---------------------------
+
@@ Documentation/gittutorial-branches.adoc (new)
+branches differently in different situations, so it might be useful for
+you to think about which is closest to your situation.
+
-+1. Abdul is making his first contribution to Python, a large open
++1. Anita is using Git on her own to write her PhD thesis with LaTeX.
++2. Bruno is making his first contribution to Python, a large open
+ source project.
-+2. Betsy is a Go developer for a social media website which has 100
++3. Carmen is a Go developer for a social media website which has 100
+ other software developers. All of her changes need to be reviewed by a
+ coworker before they're released.
-+3. Carmen and Daniela are building a website for their local cat
++4. Daniela and Emilia are building a website for their local cat
+ shelter. They're the only two people on the project.
-+4. Emilia is using Git on her own to write her PhD thesis with LaTeX.
+
++[[intro]]
+Why use branches?
+-----------------
+
@@ Documentation/gittutorial-branches.adoc (new)
+`Another update to README.md` could originally have been created on a
+different branch that was deleted after merging it into `main`.
+
-+The practical part
-+------------------
++[[tutorial]]
++Step-by-step tutorial
++---------------------
+
+Now let's talk about how to actually use branches.
+
@@ Documentation/gittutorial-branches.adoc (new)
+First, create an empty directory, move into it, and start a new Git repository:
+
+----
-+mkdir myproject
-+cd myproject
-+git init
++$ mkdir myproject
++$ cd myproject
++$ git init
+----
+
+Then open your text editor and create a file called `README.md`, with
@@ Documentation/gittutorial-branches.adoc (new)
+Then add the file and commit it, by running these commands:
+
+----
-+git add README.md
-+git commit -m "Initial commit"
++$ git add README.md
++$ git commit -m "Initial commit"
+----
+
+Next, edit README.md and make another commit, like this:
+
+----
-+git commit -am "Update README.md"
++$ git commit -am "Update README.md"
+----
+
+`git commit -am` commits the current version of all files that Git is
@@ Documentation/gittutorial-branches.adoc (new)
+
+
+----
-+git log --oneline
++$ git log --oneline
+----
+
+The output should look something like this, though with
@@ Documentation/gittutorial-branches.adoc (new)
+We're only going to talk about 2 kinds of decorations here:
+`(main)` and `(HEAD -> main)`. Here's how to read each of them:
+
-+- `e9c0b17 (main)` means that `e9c0b17` is the latest commit on the `main` branch.
++- `e9c0b17 (main)` means that `e9c0b17` is the latest commit
++ on the `main` branch.
+- `e9c0b17 (HEAD -> main)` means that `e9c0b17` is the latest commit on
+ the `main` branch, AND that `main` is the current branch.
+
@@ Documentation/gittutorial-branches.adoc (new)
+Now make a third commit, by editing `README.md` again, and running this command:
+
+----
-+git commit -am "Another update to README.md"
++$ git commit -am "Another update to README.md"
+----
+
+Now run `git log --oneline` again to see how our branch looks now.
@@ Documentation/gittutorial-branches.adoc (new)
+First, create the branch and switch to it, by running this command:
+
+----
-+git switch -c add-fruits
++$ git switch -c add-fruits
+----
+
+The `-c` flag stands for "create". You should see the output:
@@ Documentation/gittutorial-branches.adoc (new)
+some fruits in it. Then add it and commit, like this:
+
+----
-+git add fruits.txt
-+git commit -m "Add fruit list"
++$ git add fruits.txt
++$ git commit -m "Add fruit list"
++----
++
++Now edit `fruits.txt` again and commit it again, so that we can see what
++it looks like when you make 2 commits on a branch.
++
++----
++$ git add fruits.txt
++$ git commit -m "Update fruit list"
+----
+
+Run `git log --oneline` again to get a list of all the commits on the
+current branch.
+
+----
-+cd4bb48 (HEAD -> add-fruits) Add fruit list
++36d0cbf (HEAD -> add-fruits) Update fruit list
++cd4bb48 Add fruit list
+37634fd (main) Another update to README.md
+e9c0b17 Update README.md
+2e018a5 Initial commit
@@ Documentation/gittutorial-branches.adoc (new)
+See <<read_oneline,How to read `git log --oneline`'s output>> above for
+an explanation of how to interpret this output.
+
-+To summarize, this tells us that there's been 1 commit ("Add fruit list")
-+since our `add-fruits` branch split off from the `main` branch.
++To summarize, this tells us that there have been 2 commits
++("Add fruit list" and "Update fruit list") since our `add-fruits` branch
++split off from the `main` branch.
++
++3 ways to think about a branch
++------------------------------
++
++In Git there are always 3 ways to think about a branch, and different
++commands will treat a branch in different ways. For example, let's look
++at the 3 ways to think about this `add-fruits` branch.
++
++-----
++* 36d0cbf (HEAD -> add-fruits) Update fruit list
++* cd4bb48 Add fruit list
++* 37634fd (main) Another update to README.md
++* e9c0b17 Update README.md
++* 2e018a5 Initial commit
++-----
++
++We can think of the `add-fruits` branch as:
++
++1. Just the 2 commits that "branched off" of the `main` branch
++ (`cd4bb48` and `36d0cbf`).
++2. The full history of the branch since the beginning of the repository,
++ including all the commits on `main` (5 commits in this case).
++ For example, `git log add-fruits` will show you the full history.
++3. Just the latest commit on that branch (`36d0cbf`).
++ For example, `git show add-fruits` will show you the latest commit.
+
+Step 6: Get a list of all branches
+----------------------------------
@@ Documentation/gittutorial-branches.adoc (new)
+You can get a list of all branches by running this command:
+
+----
-+git branch
++$ git branch
+----
+
+The output should look like this:
@@ Documentation/gittutorial-branches.adoc (new)
+Change your current branch to `main` by running:
+
+----
-+git switch main
++$ git switch main
+----
+
+This command:
@@ Documentation/gittutorial-branches.adoc (new)
+README.md
+-----
+
++[NOTE]
++Older Git tutorials used `git checkout` to switch branches.
++`git switch` is a newer command which is easier to learn because it
++only has one job.
++
+Step 8: Create another branch
+-----------------------------
+
@@ Documentation/gittutorial-branches.adoc (new)
+branches to show what the process of working on multiple changes at the
+same time looks like.
+
-+First, switch back to the `main` branch. This is important because
-+normally when you start a new branch, you'll start it from the
-+current `main`.
-+
-+We normally start from `main` because if you create a branch called `two`
-+while on the `one` branch, merging `two` into `main` will also
-+merge `one`. Starting from `main` keeps all the branches separate.
++You'll usually want to start all new branches from the `main` branch
++to keep your branches independent from each other. Right now
++we're on the `add-fruits` branch, so we need to switch back to the
++`main` branch:
+
+-----
-+git switch main
++$ git switch main
+-----
+
+Then create a branch called `add-animals`.
+
+-----
-+git switch -c add-animals
++$ git switch -c add-animals
+-----
+
+Now create a file named `animals.txt` with some animal names in it, add
+it, and commit it.
+
+-----
-+git add animals.txt
-+git commit -m "Add animal list"
++$ git add animals.txt
++$ git commit -m "Add animal list"
+-----
+
+Step 9: Look at our branches and commits
@@ Documentation/gittutorial-branches.adoc (new)
+Run this command to show all branches and commits:
+
+-----
-+git log --oneline --graph --all
++$ git log --oneline --graph --all
+-----
+
+The output should look like this:
+
+-----
+* 1ceb7b4 (HEAD -> add-animals) Add animal list
-+| * cd4bb48 (add-fruits) Add fruit list
++| * 36d0cbf (add-fruits) Update fruit list
++| * cd4bb48 Add fruit list
+|/
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
@@ Documentation/gittutorial-branches.adoc (new)
+
+-----
+* 1ceb7b4 (HEAD -> add-animals) Add animal list
-+| * cd4bb48 (add-fruits) Add fruit list
++| * 36d0cbf (add-fruits) Update fruit list
++| * cd4bb48 Add fruit list
+|/
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
@@ Documentation/gittutorial-branches.adoc (new)
+See <<read_oneline,How to read `git log --oneline`'s output>> above for
+how to read the decorations like `(main)` or `(HEAD -> add-animals)`.
+
-+Overall this shows that the `add-animals` and `add-fruits` branches have
-+both added one new commit since they split off from the `main` branch.
++Overall this shows that the `add-animals` branch has added 1 commit and
++`add-fruits` has added 2 commits since they split off from the `main`
++branch.
+
+Step 10: Merge the `add-animals` branch into `main`
+---------------------------------------------------
@@ Documentation/gittutorial-branches.adoc (new)
+Merge `add-animals` into the main branch by running these two commands:
+
+----
-+git switch main
-+git merge add-animals
++$ git switch main
++$ git merge add-animals
+----
+
+The output should look like this:
@@ Documentation/gittutorial-branches.adoc (new)
+Step 11: Delete the `add-animals` branch
+----------------------------------------
+
-+Now that you've integrated `add-animals` branch into `main`, you can
++Now that you've integrated the `add-animals` branch into `main`, you can
+safely delete it. Delete the branch by running this command. `-d` stands
+for "delete":
+
+-----
-+git branch -d add-animals
++$ git branch -d add-animals
+-----
+
+Running this is safe: it'll refuse to delete any branch that hasn't
@@ Documentation/gittutorial-branches.adoc (new)
+and commits again:
+
+-----
-+git log --oneline --graph --all
++$ git log --oneline --graph --all
+-----
+
+The output should look like this:
+
+-----
-+* cd4bb48 (add-fruits) Add fruit list
-+| * 1ceb7b4 (HEAD -> main) Add animal list
++* 1ceb7b4 (HEAD -> main) Add animal list
++| * 36d0cbf (add-fruits) Update fruit list
++| * cd4bb48 Add fruit list
+|/
+* 37634fd Another update to README.md
+* e9c0b17 Update README.md
@@ Documentation/gittutorial-branches.adoc (new)
+Now run `git merge` to see what happens:
+
+----
-+git merge --no-edit add-fruits
++$ git merge --no-edit add-fruits
+----
+
+The `--no-edit` option tells `git merge` to use the default commit
@@ Documentation/gittutorial-branches.adoc (new)
+Once the branch is merged, delete it by running:
+
+----
-+git branch -d add-fruits
++$ git branch -d add-fruits
+----
+
+To see what `git merge` did, run `git log --oneline --graph` again.
+
+----
-+* e3c630d (HEAD -> main) Merge branch 'add-fruits'
++* 576d053 (HEAD -> main) Merge branch 'add-fruits'
+|\
++| * 36d0cbf Update fruit list
+| * cd4bb48 Add fruit list
+* | 1ceb7b4 Add animal list
+|/
@@ Documentation/gittutorial-branches.adoc (new)
+* 2e018a5 Initial commit
+----
+
-+Here you can see that it created a new commit `e3c630d`. This commit
++Here you can see that it created a new commit `576d053`. This commit
+looks different from the other commits because it has two parents:
-+cd4bb48 ("Add fruit list") and 1ceb7b4 ("Add animal list"). This kind
++`36d0cbf` ("Update fruit list") and `1ceb7b4` ("Add animal list"). This kind
+of commit with two parents is called a "merge commit".
+
-+Note: merge conflicts
-+---------------------
-+
-+Git has an automatic merge algorithm to combine the code from two
-+branches. In the example from Step 13, it's simple: one side added
-+`fruits.txt` and the other side added `animals.txt`, so the merge adds
-+both files.
-+
-+But if the two branches both edited the same lines of the same files,
-+Git will ask you to decide how to handle it. This is called a "merge
-+conflict".
-+
-+See linkgit:gitmergeconflicts[7] (`git help mergeconflicts`) for a
-+guide to handling merge conflicts.
-+
-+3 ways to think about branches
-+------------------------------
-+
-+In Git there are always 3 ways to think about a branch, and different
-+commands will treat a branch in different ways. For example, let's look
-+at the earlier setup again with the `add-fruits` branch. It has a `main`
-+branch with 3 commits on it, and an `add-fruits` branch with one commit.
-+
-+-----
-+ * cd4bb48 (add-fruits) Add fruit list
-+ /
-+* 37634fd (main) Another update to README.md
-+* e9c0b17 Update README.md
-+* 2e018a5 Initial commit
-+-----
-+
-+We can think of the `add-fruits` branch as:
-+
-+1. Just the 1 commit that "branched off" of the `main` branch (`cd4bb48`).
-+2. The full history of the branch since the beginning of the repository,
-+ including all the commits on `main` (4 commits in this case).
-+ For example, `git log add-fruits` will show you the full history.
-+3. Just the latest commit on that branch.
-+ For example, `git show add-fruits` will show you the latest commit.
++[NOTE]
++If you merge two branches which both edited the same lines of the
++same files, Git will ask you to decide how to handle it. This is
++called a "merge conflict". See linkgit:gitmergeconflicts[7]
++(`git help mergeconflicts`) for a guide to handling merge conflicts.
+
-+How to use branches to collaborate: it depends
-+----------------------------------------------
++[[workflows]]
++Examples of using branches to collaborate
++-----------------------------------------
+
+There are lots of ways to use branches to collaborate with other people.
+We don't have space for a full guide to collaborating with Git here, but
-+after a very quick introduction to `git pull`, we'll give examples of
++we'll give a quick introduction to `git pull` and examples of
+how each of our characters from the beginning might use branches.
+
+In these examples we're going to use `git push`, `git pull`, `git
+clone`, and `git remote add`. For a basic introduction to `git push` and
+`git remote add`, see Step 14 of linkgit:gittutorial[7].
+
-+Using `git pull`: the basics
-+----------------------------
++Intro to `git pull`
++-------------------
+
+Here's the simplest way to use `git pull`.
+
@@ Documentation/gittutorial-branches.adoc (new)
+branch.
+
+-------
-+git clone https://example.com/example.git
++$ git clone https://example.com/example.git
+-------
+
+After cloning a repository, you can run `git pull` while on the main
+branch to update it with the latest version, like this:
+
+-------
-+git switch main
-+git pull
++$ git switch main
++$ git pull
+-------
+
+This is all you need to know about `git pull` to understand these
+examples.
+
-+Example: Emilia the PhD student
-+-------------------------------
++Example: Anita the PhD student
++------------------------------
+
-+Emilia is writing her PhD thesis. She follows the steps from
++Anita is writing her PhD thesis. She follows the steps from
+linkgit:gittutorial[7] to set up a Git repository on the Internet so
+that she can back up her work.
+
+To back up her work after making a commit, she runs:
+
+----
-+git push origin main
++$ git push origin main
+----
+
+Sometimes, she creates a branch to make an experimental change she's not
@@ Documentation/gittutorial-branches.adoc (new)
+She does this by running:
+
+----
-+git switch -c rewrite-chapter-5
++$ git switch -c rewrite-chapter-5
+----
+
-+If she decides that the experimental change should be merged, she merges
++Then she makes an experimental change, like rewriting Chapter 5 and commits it.
++If she decides that the change should be merged, she merges
+it into `main` like this:
+
+----
-+git switch main
-+git merge rewrite-chapter-5
++$ git switch main
++$ git merge rewrite-chapter-5
+----
+
+Or if she decides the rewrite of chapter 5 was a bad idea, she can
-+delete the branch:
++switch back to `main` and delete the branch:
+
+----
-+git branch -D rewrite-chapter-5
++$ git switch main
++$ git branch -D rewrite-chapter-5
+----
+
-+Example: Abdul the open source contributor
++Example: Bruno the open source contributor
+------------------------------------------
+
-+Abdul is contributing to an open source project for the first time.
++Bruno is contributing to an open source project for the first time.
+
+First, he finds the official Git repository for the project and clones
+it, like this:
+
+----
-+git clone https://example.com/project/project
++$ git clone https://example.com/project/project
+----
+
+He doesn't have permission to push changes directly to that
+project, so he creates his own copy of the repository at
-+https://example.com/abdul/project.
++https://example.com/bruno/project.
+
+Then he adds that repository as a second remote, like this:
+
+----
-+git remote add abdul https://example.com/abdul/project
++$ git remote add bruno https://example.com/bruno/project
+----
+
+Before starting work on his branch, he makes sure that he has the
+latest version of the `main` branch using `git pull`, like this:
+
+----
-+git switch main
-+git pull
++$ git switch main
++$ git pull
+----
+
+Then he creates a new branch, like this:
+
+----
-+git switch -c new-feature
++$ git switch -c new-feature
+----
+
+Once he's done with his branch, he pushes the branch to his Git
+repository, like this:
+
+----
-+git push abdul new-feature
++$ git push bruno new-feature
+----
+
+Then he goes through the open source project's process to submit his
+branch for review.
+
-+Example: Betsy the corporate employee
-+-------------------------------------
++Example: Carmen the corporate employee
++--------------------------------------
+
+On her first day of work, she clones the company's Git repository by
+running:
+
+----
-+git clone git@example.com:company/project
++$ git clone git@example.com:company/project
+----
+
+She has access to push new branches to this repository with her work,
@@ Documentation/gittutorial-branches.adoc (new)
+latest version of the `main` branch using `git pull`, like this:
+
+----
-+git switch main
-+git pull
++$ git switch main
++$ git pull
+----
+
+Then she creates a new branch, like this:
+
+----
-+git switch -c new-feature
++$ git switch -c new-feature
+----
+
+Once she's done with her branch, she pushes the branch to the company
+Git repository, like this:
+
+----
-+git push origin new-feature
++$ git push origin new-feature
+----
+
+Then she goes through her company's process for getting branches merged.
+
-+Example: Daniela and Carmen with the cat shelter website
++Example: Daniela and Emilia with the cat shelter website
+--------------------------------------------------------
+
-+Daniela and Carmen create a Git repository for their cat shelter website.
++Daniela and Emilia create a Git repository for their cat shelter website.
+
+They both clone it onto their computer like this:
+
+----
-+git clone git@example.com:cat-shelter/kitties.git
++$ git clone git@example.com:cat-shelter/kitties.git
+----
+
+They decide to work together by just pushing all of their commits to the
+`main` branch, without using any other branches.
+
-+When Daniela wants to do work, she first runs `git pull` on the main
++When Emilia wants to do work, she first runs `git pull` on the main
+branch, like this:
+
+----
-+git pull
++$ git pull
+----
+
-+She also checks in with Carmen to make sure they won't be working on
-+the same files. Then she works on her changes. Then, before pushing her
-+changes, she runs this command to merge any changes Carmen has made.
++She also checks in with Daniela to make sure they won't be working on
++the same files. Then she works on her changes and commits them.
++Then, before pushing her changes, she runs this command to merge any
++changes Daniela has made.
+
+----
-+git pull --no-rebase
++$ git pull --no-rebase
+----
+
+We don't have space for a full introduction to linkgit:git-pull[1]
-+here, but `git pull` fetches Carmen's changes and merges them into the
++here, but `git pull` fetches Daniela's changes and merges them into the
+current branch. The `--no-rebase` flag tells Git to use `git merge` to
+do the merge.
+
+Then she pushes her changes with:
+
+----
-+git push
++$ git push
+----
+
++[[tip]]
+Tip: put your current branch in your shell prompt
+-------------------------------------------------
+
Documentation/Makefile | 1 +
Documentation/gittutorial-branches.adoc | 964 ++++++++++++++++++++++++
Documentation/meson.build | 1 +
command-list.txt | 1 +
4 files changed, 967 insertions(+)
create mode 100644 Documentation/gittutorial-branches.adoc
diff --git a/Documentation/Makefile b/Documentation/Makefile
index b574ca2044..4f3fc9a97f 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -65,6 +65,7 @@ MAN7_TXT += gitremote-helpers.adoc
MAN7_TXT += gitrevisions.adoc
MAN7_TXT += gitsubmodules.adoc
MAN7_TXT += gittutorial-2.adoc
+MAN7_TXT += gittutorial-branches.adoc
MAN7_TXT += gittutorial.adoc
MAN7_TXT += gitworkflows.adoc
diff --git a/Documentation/gittutorial-branches.adoc b/Documentation/gittutorial-branches.adoc
new file mode 100644
index 0000000000..579975ba4d
--- /dev/null
+++ b/Documentation/gittutorial-branches.adoc
@@ -0,0 +1,964 @@
+gittutorial-branches(7)
+=======================
+
+NAME
+----
+gittutorial-branches - How to use branches
+
+DESCRIPTION
+-----------
+
+This is part of a 2-part series on Git for beginners:
+
+- Part 1 (linkgit:gittutorial[7]): Introduction to commits and `git push`
+- Part 2 (you are here): Introduction to branches
+
+This tutorial contains:
+
+1. <<intro,An introduction to branches>>
+2. <<tutorial,A step-by-step practical tutorial>>
+3. <<workflows,Example collaboration workflows>>
+4. <<tip,Tips, GUI tools, and where to learn more>>
+
+
+Meet some example Git users
+---------------------------
+
+To start, we're going to introduce a few imaginary people who are learning
+to use Git branches for the first time. This is because people use
+branches differently in different situations, so it might be useful for
+you to think about which is closest to your situation.
+
+1. Anita is using Git on her own to write her PhD thesis with LaTeX.
+2. Bruno is making his first contribution to Python, a large open
+ source project.
+3. Carmen is a Go developer for a social media website which has 100
+ other software developers. All of her changes need to be reviewed by a
+ coworker before they're released.
+4. Daniela and Emilia are building a website for their local cat
+ shelter. They're the only two people on the project.
+
+[[intro]]
+Why use branches?
+-----------------
+
+Branches are a tool to organize your work and collaborate. For example,
+if you're working on a website, you might be working on multiple
+unrelated changes at the same time, like:
+
+* an update to the FAQ
+* making the website faster
+* adding a translation into Bengali
+
+With branches, you can work on each change at its own pace without them
+interfering with each other.
+
+The "tree" mental model of branches
+-----------------------------------
+
+A useful mental model for Git branches is a tree where the "trunk"
+is the main branch, and there are other branches branching "off" of
+main.
+
+Each of the branches branching off has only a few commits of their own.
+When you finish working on a branch, you can merge its commits back into
+the main branch. This is where the metaphor starts to break down: in a
+real tree, branches that branch off from the trunk don't merge back in
+later, but in Git they can.
+
+For example, here's an ASCII art diagram of a Git repository. The most
+recent commits are at the top. The main branch is in the center and the
+others come off the sides.
+
+---------
+ \ |
+ \| /
+ |/
+ |
+ |
+ |
+---------
+
+This mental model doesn't represent every single thing you can do with
+Git branches, but you can go a long way with it.
+
+[NOTE]
+When the Git documentation uses the word "tree", it means something more
+like "directory tree of files", which is a completely different concept.
+If you want some jargon: the computer science term for "a tree where the
+branches can come back together" is "directed acyclic graph".
+
+The main branch
+---------------
+
+When you run `git init`, Git creates a default branch. Usually this is
+called `main` or `master`. Git mostly doesn't treat this branch in any
+special way (you could even delete that branch if you really want!),
+but for most people using Git this branch does have a special meaning.
+For example:
+
+* In an open source project like Python, the "main" branch might have
+ changes that the maintainers have approved to be in a future release
+* A website's "main" branch might be deployed to the server every time
+ it's updated
+* A PhD student's "main" branch might have the latest version of their
+ PhD thesis
+
+When joining a new project, it's important to understand how that
+project uses its main branch.
+
+In this tutorial we'll call this branch `main`.
+
+Some important facts about Git commits
+--------------------------------------
+
+Before explaining how branches work, here are some important facts about
+Git commits.
+
+**Every commit has an ID**. The ID is made of the numbers 0-9 and letters
+a-f, for example `501584c1bf29ab88e815c09ffb99c887da81241c`. You can
+find the current commit's ID by running `git log`: it's on the first
+line. In this tutorial you're going to see a lot of "short" commit IDs
+(for example `501584c`), which are the first 7 characters or so of the
+commit ID.
+
+**Commits never change**. If you have a commit ID, then the files,
+author, and history of that commit with that ID will never change in any
+way. This is one of Git's biggest strengths, but it also has drawbacks.
+It guarantees that if you have a commit's ID then you can always get
+back its exact contents, but it also makes it difficult to change old
+commits. For example, if someone changes their email address and wants
+to update it on their old commits, it can be very disruptive. You'd need
+to replace all the old commits with new commits with a different email
+address.
+
+**Every commit has a parent** (except the first commit).
+This means that if you have a commit ID, you can follow the pointers to
+the commit's parent(s) to get the whole history of the project up to that
+point.
+
+See linkgit:gitdatamodel[7] for more about how Git represents commits.
+
+
+How Git represents branches
+---------------------------
+
+Even though the way people think about the "main" branch and other
+branches is quite different (one is the "trunk", the others "branch off"
+of main), Git represents all branches in the same way.
+
+Git stores branches as a name and a commit ID. They're stored in the
+`.git` directory in your local Git repository, for example:
+
+----
+main: 37634fd
+add-fruits: cd4bb48
+----
+
+At first, this might seem totally unrelated to the "tree" mental model
+we talked about before. But because every commit has a reference to its
+parent, Git can follow the links from a commit to its parent to get the
+structure (the "tree") of the whole repository.
+
+For example, in this ASCII diagram, the commit below a commit is its
+parent:
+
+-------
+ * cd4bb48 (latest 'add-fruits' commit) Add fruit list
+ /
+* 37634fd (latest 'main' commit) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-------
+
+Branches are very cheap to create: when you create a new branch, Git
+just needs to store one commit ID. But this also means that we don't
+always know the history of how a branch evolved over time. For example
+`Another update to README.md` could originally have been created on a
+different branch that was deleted after merging it into `main`.
+
+[[tutorial]]
+Step-by-step tutorial
+---------------------
+
+Now let's talk about how to actually use branches.
+
+This tutorial is from the point of view of someone who's using branches
+to organize their own work, because it's simpler. There are some
+examples at the end of how this might change if you're using Git to
+collaborate, like one of the example users at the beginning.
+
+Step 1: Create an empty repository with two commits
+---------------------------------------------------
+
+Before we start working with branches, we need a Git repository to work
+with.
+
+First, create an empty directory, move into it, and start a new Git repository:
+
+----
+$ mkdir myproject
+$ cd myproject
+$ git init
+----
+
+Then open your text editor and create a file called `README.md`, with
+these contents:
+
+-----
+This is an example file.
+It has two lines.
+-----
+
+Then add the file and commit it, by running these commands:
+
+----
+$ git add README.md
+$ git commit -m "Initial commit"
+----
+
+Next, edit README.md and make another commit, like this:
+
+----
+$ git commit -am "Update README.md"
+----
+
+`git commit -am` commits the current version of all files that Git is
+tracking.
+
+Now we're set up and we can start creating branches.
+
+Step 2: Find your current branch
+--------------------------------
+
+In Git, you normally have a "current branch". You can see your current
+branch by running `git status`. It's usually on the first line, like this:
+
+----
+$ git status
+
+On branch main
+----
+
+Step 3: Look at the commits on your current branch
+--------------------------------------------------
+
+Run this command to get a list of all commits on your current
+branch.
+
+
+----
+$ git log --oneline
+----
+
+The output should look something like this, though with
+different commit IDs:
+
+----
+e9c0b17 (HEAD -> main) Update README.md
+2e018a5 Initial commit
+----
+
+In this tutorial, we're going to use `git log --oneline` over and over
+again to visualize our branch. If you have a Git GUI installed, its
+visualization might be easier to read.
+See <<guis,GUI tools>> for a list of GUIs.
+
+[[read_oneline]]
+How to read `git log --oneline`'s output
+----------------------------------------
+
+In `git log`'s output, the latest commit is at the top.
+Here's an example of what the output might look like:
+
+----
+e9c0b17 (HEAD -> main) Update README.md
+2e018a5 Initial commit
+----
+
+Each line has 3 parts:
+
+1. The commit ID (like `e9c0b17`)
+2. Optional extra info (like `(HEAD -> main)`). Git calls this a "decoration".
+3. The commit message (like `Update README.md`)
+
+We're only going to talk about 2 kinds of decorations here:
+`(main)` and `(HEAD -> main)`. Here's how to read each of them:
+
+- `e9c0b17 (main)` means that `e9c0b17` is the latest commit
+ on the `main` branch.
+- `e9c0b17 (HEAD -> main)` means that `e9c0b17` is the latest commit on
+ the `main` branch, AND that `main` is the current branch.
+
+[NOTE]
+`HEAD` is a special file in the `.git` directory where Git stores the
+name of your current branch. So you can read `HEAD -> main` as "current
+branch is main".
+
+Step 4: Make another commit
+---------------------------
+
+When you make a new commit, Git updates your current branch to point
+at that commit. Right now, `git log --oneline` looks like this, because
+we've made 2 commits:
+
+----
+e9c0b17 (HEAD -> main) Update README.md
+2e018a5 Initial commit
+----
+
+Now make a third commit, by editing `README.md` again, and running this command:
+
+----
+$ git commit -am "Another update to README.md"
+----
+
+Now run `git log --oneline` again to see how our branch looks now.
+
+----
+37634fd (HEAD -> main) Another update to README.md
+e9c0b17 Update README.md
+2e018a5 Initial commit
+----
+
+This shows us that the latest commit on the `main` branch is now
+"Another update to README.md".
+
+Step 5: Create a branch
+-----------------------
+
+Here's how to create a new branch and make a commit on it. We're going
+to create a branch called `add-fruits` that adds a list of fruits.
+
+First, create the branch and switch to it, by running this command:
+
+----
+$ git switch -c add-fruits
+----
+
+The `-c` flag stands for "create". You should see the output:
+
+----
+Switched to a new branch 'add-fruits'
+----
+
+Now, in your text editor, create a new file called `fruits.txt` with
+some fruits in it. Then add it and commit, like this:
+
+----
+$ git add fruits.txt
+$ git commit -m "Add fruit list"
+----
+
+Now edit `fruits.txt` again and commit it again, so that we can see what
+it looks like when you make 2 commits on a branch.
+
+----
+$ git add fruits.txt
+$ git commit -m "Update fruit list"
+----
+
+Run `git log --oneline` again to get a list of all the commits on the
+current branch.
+
+----
+36d0cbf (HEAD -> add-fruits) Update fruit list
+cd4bb48 Add fruit list
+37634fd (main) Another update to README.md
+e9c0b17 Update README.md
+2e018a5 Initial commit
+----
+
+See <<read_oneline,How to read `git log --oneline`'s output>> above for
+an explanation of how to interpret this output.
+
+To summarize, this tells us that there have been 2 commits
+("Add fruit list" and "Update fruit list") since our `add-fruits` branch
+split off from the `main` branch.
+
+3 ways to think about a branch
+------------------------------
+
+In Git there are always 3 ways to think about a branch, and different
+commands will treat a branch in different ways. For example, let's look
+at the 3 ways to think about this `add-fruits` branch.
+
+-----
+* 36d0cbf (HEAD -> add-fruits) Update fruit list
+* cd4bb48 Add fruit list
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+We can think of the `add-fruits` branch as:
+
+1. Just the 2 commits that "branched off" of the `main` branch
+ (`cd4bb48` and `36d0cbf`).
+2. The full history of the branch since the beginning of the repository,
+ including all the commits on `main` (5 commits in this case).
+ For example, `git log add-fruits` will show you the full history.
+3. Just the latest commit on that branch (`36d0cbf`).
+ For example, `git show add-fruits` will show you the latest commit.
+
+Step 6: Get a list of all branches
+----------------------------------
+
+You can get a list of all branches by running this command:
+
+----
+$ git branch
+----
+
+The output should look like this:
+
+----
+* add-fruits
+ main
+----
+
+This says that you have 2 branches (`main` and `add-fruits`). The one
+with the `*` next to it is the current branch.
+
+Step 7: Switch branches
+-----------------------
+
+Change your current branch to `main` by running:
+
+----
+$ git switch main
+----
+
+This command:
+
+1. Updates the files in your working directory to match the `main` branch.
+ For example, if `main` is at the commit `aa33bb`, then `git switch main`
+ will give you the files from the commit `aa33bb`.
+2. Sets your current branch to `main`, so that any new commits
+ you make will be on that branch
+
+
+Run `ls`. You should see that the new `fruits.txt` file you created is gone:
+
+-----
+$ git switch main
+$ ls
+README.md
+-----
+
+Of course, `fruits.txt` is not actually gone: it's stored in the `.git`
+directory and we can switch back to the `add-fruits` branch to get it
+back.
+
+Run `git switch add-fruits` to switch back to the `add-fruits`
+branch, and run `ls` again. The `fruits.txt` file should reappear:
+
+-----
+$ git switch add-fruits
+$ ls
+fruits.txt
+README.md
+-----
+
+[NOTE]
+Older Git tutorials used `git checkout` to switch branches.
+`git switch` is a newer command which is easier to learn because it
+only has one job.
+
+Step 8: Create another branch
+-----------------------------
+
+Now create a second branch called `add-animals`. We're creating two
+branches to show what the process of working on multiple changes at the
+same time looks like.
+
+You'll usually want to start all new branches from the `main` branch
+to keep your branches independent from each other. Right now
+we're on the `add-fruits` branch, so we need to switch back to the
+`main` branch:
+
+-----
+$ git switch main
+-----
+
+Then create a branch called `add-animals`.
+
+-----
+$ git switch -c add-animals
+-----
+
+Now create a file named `animals.txt` with some animal names in it, add
+it, and commit it.
+
+-----
+$ git add animals.txt
+$ git commit -m "Add animal list"
+-----
+
+Step 9: Look at our branches and commits
+----------------------------------------
+
+In Git it's extremely useful to be able to visualize your branches.
+There are many GUIs built by the community which can do this, but in
+this tutorial we're going to use the command line because it's the only
+interface we can guarantee everyone reading the tutorial has.
+
+Run this command to show all branches and commits:
+
+-----
+$ git log --oneline --graph --all
+-----
+
+The output should look like this:
+
+-----
+* 1ceb7b4 (HEAD -> add-animals) Add animal list
+| * 36d0cbf (add-fruits) Update fruit list
+| * cd4bb48 Add fruit list
+|/
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+How to read `git log --graph`'s output
+--------------------------------------
+
+`git log --oneline --graph --all` prints out a text-based visualization
+of all your Git branches and their history.
+
+This isn't the best visualization, but to use branches well you need
+some way to get this information, and it's the only visualization the
+command line Git interface has. Almost every Git GUI will have another
+visualization you can use.
+
+Here's some example output:
+
+-----
+* 1ceb7b4 (HEAD -> add-animals) Add animal list
+| * 36d0cbf (add-fruits) Update fruit list
+| * cd4bb48 Add fruit list
+|/
+* 37634fd (main) Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+How to read this:
+
+* Every `*` is a commit
+* As usual with `git log`, the latest commit is at the top
+* The `|` and `/` are ASCII art lines that Git uses to show
+ what the parents of a commit are. Here they're showing that `37634fd`
+ is the parent of both `cd4bb48` and `1ceb7b4`.
+
+See <<read_oneline,How to read `git log --oneline`'s output>> above for
+how to read the decorations like `(main)` or `(HEAD -> add-animals)`.
+
+Overall this shows that the `add-animals` branch has added 1 commit and
+`add-fruits` has added 2 commits since they split off from the `main`
+branch.
+
+Step 10: Merge the `add-animals` branch into `main`
+---------------------------------------------------
+
+Now imagine that you're done with your work on the `add-animals` branch, and
+you're ready to bring that work onto your `main` branch.
+
+Right now `add-animals` is one commit "ahead" of the `main` branch.
+To bring all the work in `add-animals` into `main`, we can just move
+`main` forward to match the `add-animals` branch.
+
+This is the simplest possible situation when trying to bring the work
+from one branch into another branch, and Git calls it a **fast-forward
+merge**.
+
+Merge `add-animals` into the main branch by running these two commands:
+
+----
+$ git switch main
+$ git merge add-animals
+----
+
+The output should look like this:
+
+----
+Updating 37634fd..1ceb7b4
+Fast-forward
+ animals.txt | 1 +
+ 1 file changed, 1 insertion(+)
+ create mode 100644 animals.txt
+----
+
+The `Fast-forward` output means that this was a fast-forward merge.
+
+Step 11: Delete the `add-animals` branch
+----------------------------------------
+
+Now that you've integrated the `add-animals` branch into `main`, you can
+safely delete it. Delete the branch by running this command. `-d` stands
+for "delete":
+
+-----
+$ git branch -d add-animals
+-----
+
+Running this is safe: it'll refuse to delete any branch that hasn't
+already been integrated into the current branch.
+
+It's useful to delete branches after they've been merged because it
+stops them from cluttering up your branch list (from `git branch`).
+
+Step 12: Look at our branches and commits again
+-----------------------------------------------
+
+Now that we've made some changes, run this command to show all branches
+and commits again:
+
+-----
+$ git log --oneline --graph --all
+-----
+
+The output should look like this:
+
+-----
+* 1ceb7b4 (HEAD -> main) Add animal list
+| * 36d0cbf (add-fruits) Update fruit list
+| * cd4bb48 Add fruit list
+|/
+* 37634fd Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+-----
+
+Step 13: Merge the `add-fruits` branch into `main`
+--------------------------------------------------
+
+The output from the last step shows that we still have an `add-fruits`
+branch that's branched off a previous version of the `main` branch.
+
+In this situation where `main` and `add-fruits` both have new commits,
+we say that the two branches have "diverged". Having diverged branches
+is very common when working together on a team, because usually on a
+large team many people are making commits at the same time.
+
+If two branches have diverged, you still use the command `git merge`
+to combine them, but it does something different from our previous merge
+in Step 10.
+
+Now run `git merge` to see what happens:
+
+----
+$ git merge --no-edit add-fruits
+----
+
+The `--no-edit` option tells `git merge` to use the default commit
+message. Normally `git merge` will open a text editor to ask you to
+write a commit message, but we're skipping that step here.
+
+You should see the output:
+
+----
+Merge made by the 'ort' strategy.
+ fruits.txt | 1 +
+ 1 file changed, 1 insertion(+)
+ create mode 100644 fruits.txt
+----
+
+Once the branch is merged, delete it by running:
+
+----
+$ git branch -d add-fruits
+----
+
+To see what `git merge` did, run `git log --oneline --graph` again.
+
+----
+* 576d053 (HEAD -> main) Merge branch 'add-fruits'
+|\
+| * 36d0cbf Update fruit list
+| * cd4bb48 Add fruit list
+* | 1ceb7b4 Add animal list
+|/
+* 37634fd Another update to README.md
+* e9c0b17 Update README.md
+* 2e018a5 Initial commit
+----
+
+Here you can see that it created a new commit `576d053`. This commit
+looks different from the other commits because it has two parents:
+`36d0cbf` ("Update fruit list") and `1ceb7b4` ("Add animal list"). This kind
+of commit with two parents is called a "merge commit".
+
+[NOTE]
+If you merge two branches which both edited the same lines of the
+same files, Git will ask you to decide how to handle it. This is
+called a "merge conflict". See linkgit:gitmergeconflicts[7]
+(`git help mergeconflicts`) for a guide to handling merge conflicts.
+
+[[workflows]]
+Examples of using branches to collaborate
+-----------------------------------------
+
+There are lots of ways to use branches to collaborate with other people.
+We don't have space for a full guide to collaborating with Git here, but
+we'll give a quick introduction to `git pull` and examples of
+how each of our characters from the beginning might use branches.
+
+In these examples we're going to use `git push`, `git pull`, `git
+clone`, and `git remote add`. For a basic introduction to `git push` and
+`git remote add`, see Step 14 of linkgit:gittutorial[7].
+
+Intro to `git pull`
+-------------------
+
+Here's the simplest way to use `git pull`.
+
+When you use `git clone` to clone a repository, it checks out a branch
+by default. The branch it checks out is usually the "main" branch.
+This is the one exception to "Git mostly doesn't treat the main branch
+in any special way". Technically the repository's owner can set the
+default branch to anything, but normally they'll set it to the main
+branch.
+
+-------
+$ git clone https://example.com/example.git
+-------
+
+After cloning a repository, you can run `git pull` while on the main
+branch to update it with the latest version, like this:
+
+-------
+$ git switch main
+$ git pull
+-------
+
+This is all you need to know about `git pull` to understand these
+examples.
+
+Example: Anita the PhD student
+------------------------------
+
+Anita is writing her PhD thesis. She follows the steps from
+linkgit:gittutorial[7] to set up a Git repository on the Internet so
+that she can back up her work.
+
+To back up her work after making a commit, she runs:
+
+----
+$ git push origin main
+----
+
+Sometimes, she creates a branch to make an experimental change she's not
+sure that she's going to keep, like `rewrite-chapter-5`.
+
+She does this by running:
+
+----
+$ git switch -c rewrite-chapter-5
+----
+
+Then she makes an experimental change, like rewriting Chapter 5 and commits it.
+If she decides that the change should be merged, she merges
+it into `main` like this:
+
+----
+$ git switch main
+$ git merge rewrite-chapter-5
+----
+
+Or if she decides the rewrite of chapter 5 was a bad idea, she can
+switch back to `main` and delete the branch:
+
+----
+$ git switch main
+$ git branch -D rewrite-chapter-5
+----
+
+Example: Bruno the open source contributor
+------------------------------------------
+
+Bruno is contributing to an open source project for the first time.
+
+First, he finds the official Git repository for the project and clones
+it, like this:
+
+----
+$ git clone https://example.com/project/project
+----
+
+He doesn't have permission to push changes directly to that
+project, so he creates his own copy of the repository at
+https://example.com/bruno/project.
+
+Then he adds that repository as a second remote, like this:
+
+----
+$ git remote add bruno https://example.com/bruno/project
+----
+
+Before starting work on his branch, he makes sure that he has the
+latest version of the `main` branch using `git pull`, like this:
+
+----
+$ git switch main
+$ git pull
+----
+
+Then he creates a new branch, like this:
+
+----
+$ git switch -c new-feature
+----
+
+Once he's done with his branch, he pushes the branch to his Git
+repository, like this:
+
+----
+$ git push bruno new-feature
+----
+
+Then he goes through the open source project's process to submit his
+branch for review.
+
+Example: Carmen the corporate employee
+--------------------------------------
+
+On her first day of work, she clones the company's Git repository by
+running:
+
+----
+$ git clone git@example.com:company/project
+----
+
+She has access to push new branches to this repository with her work,
+but their system doesn't allow pushing to the `main` branch directly.
+
+Before starting work on her new feature, she makes sure that she has the
+latest version of the `main` branch using `git pull`, like this:
+
+----
+$ git switch main
+$ git pull
+----
+
+Then she creates a new branch, like this:
+
+----
+$ git switch -c new-feature
+----
+
+Once she's done with her branch, she pushes the branch to the company
+Git repository, like this:
+
+----
+$ git push origin new-feature
+----
+
+Then she goes through her company's process for getting branches merged.
+
+Example: Daniela and Emilia with the cat shelter website
+--------------------------------------------------------
+
+Daniela and Emilia create a Git repository for their cat shelter website.
+
+They both clone it onto their computer like this:
+
+----
+$ git clone git@example.com:cat-shelter/kitties.git
+----
+
+They decide to work together by just pushing all of their commits to the
+`main` branch, without using any other branches.
+
+When Emilia wants to do work, she first runs `git pull` on the main
+branch, like this:
+
+----
+$ git pull
+----
+
+She also checks in with Daniela to make sure they won't be working on
+the same files. Then she works on her changes and commits them.
+Then, before pushing her changes, she runs this command to merge any
+changes Daniela has made.
+
+----
+$ git pull --no-rebase
+----
+
+We don't have space for a full introduction to linkgit:git-pull[1]
+here, but `git pull` fetches Daniela's changes and merges them into the
+current branch. The `--no-rebase` flag tells Git to use `git merge` to
+do the merge.
+
+Then she pushes her changes with:
+
+----
+$ git push
+----
+
+[[tip]]
+Tip: put your current branch in your shell prompt
+-------------------------------------------------
+
+Accidentally doing a Git operation on the wrong branch can be really
+annoying to undo. Because of this, it's extremely useful in Git to
+always know what your current branch is.
+
+To help with this, Git comes with a shell script called `git-prompt.sh`
+that has instructions for how to make sure your current Git branch is
+always in your shell prompt. If it's not already on your machine, you can
+find it in the https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh[official Git repository here].
+There are also many shell plugins to do this.
+
+For example, if you're on the `main` branch, this can make your shell
+prompt look like this:
+
+----
+[user@host myproject (main)]$
+----
+
+[[guis]]
+GUI tools
+---------
+
+Here are a few open source GUI tools. All of them work on Linux, Mac,
+and Windows unless otherwise mentioned:
+
+- `gitk` and `git gui` both come with Git. `git gui` focuses on making
+ commits and `gitk` visualizes the project's history.
+ See linkgit:gitk[1] and linkgit:git-gui[1] for more info, and
+ https://git-scm.com/install/ for install instructions.
+- TortoiseGit (https://tortoisegit.org/) for Windows
+- GitUp (https://gitup.co/) for Mac
+
+Interactive terminal UIs:
+
+- LazyGit (https://github.com/jesseduffield/lazygit)
+- tig (https://jonas.github.io/tig/)
+
+Many text editors have Git integrations, for example:
+
+- Magit (https://magit.vc/) for Emacs
+- Fugitive (https://github.com/tpope/vim-fugitive) for Vim
+- Many IDEs (VS Code, Eclipse, JetBrains, etc) have built-in Git
+ integrations. This can be a good option if you're already using one
+ of them.
+
+Where to learn more
+-------------------
+
+- When merging two branches, there can be a conflict if both sides
+ edited the same lines of a file. linkgit:gitmergeconflicts[7]
+ (or `git help mergeconflicts`) is a guide to handling merge conflicts.
+- The UPSTREAM BRANCHES section in linkgit:git-pull[1] explains how to
+ configure where `git push` or `git pull` will push or pull from.
+- Some teams prefer to use linkgit:git-rebase[1] and a fast-forward
+ merge to combine branches instead of using merge commits.
+- linkgit:gitdatamodel[7] explains how Git represents branches and
+ commits.
+
+GIT
+---
+Part of the linkgit:git[1] suite
diff --git a/Documentation/meson.build b/Documentation/meson.build
index b290557834..23634ebd7e 100644
--- a/Documentation/meson.build
+++ b/Documentation/meson.build
@@ -208,6 +208,7 @@ manpages = {
'gitrevisions.adoc' : 7,
'gitsubmodules.adoc' : 7,
'gittutorial-2.adoc' : 7,
+ 'gittutorial-branches.adoc' : 7,
'gittutorial.adoc' : 7,
'gitworkflows.adoc' : 7,
}
diff --git a/command-list.txt b/command-list.txt
index 56d0d7ed9b..0e3e3fc378 100644
--- a/command-list.txt
+++ b/command-list.txt
@@ -245,6 +245,7 @@ gitrepository-layout userinterfaces
gitrevisions userinterfaces
gitsubmodules guide
gittutorial guide
+gittutorial-branches guide
gitweb ancillaryinterrogators
gitworkflows guide
scalar mainporcelain
base-commit: 3c60ef1e38ee80337025a1b908327f7879386329
--
gitgitgadget
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2] doc: add tutorial on branches for beginners
2026-11-24 21:13 ` [PATCH v2] " Julia Evans via GitGitGadget
@ 2026-11-30 15:09 ` D. Ben Knoble
2026-11-30 16:10 ` Julia Evans
0 siblings, 1 reply; 15+ messages in thread
From: D. Ben Knoble @ 2026-11-30 15:09 UTC (permalink / raw)
To: Julia Evans via GitGitGadget; +Cc: git, Patrick Steinhardt, Julia Evans
On Tue, Nov 24, 2026 at 4:13 PM Julia Evans via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Julia Evans <julia@jvns.ca>
>
> Because Git's branches are so flexible and the meaning of a branch is
> only what people assign to it, it's important to talk about some of the
> social context about branches. Do this in two ways:
>
> 1. Introduce some imaginary characters who are learning branches for the
> first time and examples of workflows they might use. Test readers
> said this was helpful because it helped them see different ways
> they might use branches.
> 2. Explain the importance of a "main" or "master" branch in many
> projects, and give a few examples of how projects might use it.
>
> On `git log`:
>
> - Use the output of `git log --graph` to visualize branches instead of
> a more abstract ASCII diagram, since it serves a double purpose of
> teaching people how to read `git log`'s output.
> But also mention that folks may prefer to use a GUI to visualize
> branches.
> - Include two sections to explain the output of `git log`, since several
> test readers found it very hard to understand. In that explanation,
> only explain `HEAD` fairly briefly and instead keep the focus on the
> idea of a "current branch", since that's the term Git's UI normally
> uses.
>
> On the conceptual introduction at the beginning:
>
> - One of the biggest issues with explaining branches is that there are 3
> ways in Git to think of branches and it's not straightforward to
> explain how to reconcile them:
> 1. just the commits that "branch off"
> 2. the latest commit on the branch
> 3. the full history since the beginning of time
> Handle this by starting with the "tree" metaphor where branches
> "branch off" a central trunk (way 1), since this makes sense with how
> people actually want to use branches. Point out some issues with the
> tree metaphor and talk about how it relates to the way Git represents
> branches (way 2).
> - Avoid using computer science jargon, because it's a major barrier to
> folks without a CS background. It's not useful or realistic to teach
> most beginners the term "directed acyclic graph" just so they can
> learn branches. Mention the term "directed acyclic graph" briefly in a
> note for folks who are already familiar with that term and link folks
> to the data model if they'd like more information.
> - Include some basic facts about commits. Folks seemed to find this
> helpful, one person said they didn't realize it would be so hard to
> change their email address later.
>
> To keep it readable:
> - Don't assume that the reader has read `gittutorial`, and instead
> refer back to it explicitly if it's relevant.
> - Always include the output for every command. Test readers said
> this was helpful.
>
> Other choices about material that is/isn't included:
>
> - `git-prompt.sh` (yes): Mention how important it is to be aware
> what branch you're on, and suggest using `git-prompt.sh`. Link to
> git-prompt.sh on GitHub since several test readers couldn't find it on
> their machine. The test readers liked this.
> - fast-forward merges (yes): Explain the difference between a fast-forward
> merge and a merge commit by giving examples of what each one looks
> like.
> - upstreams/rebase (no): Don't explain what an upstream is or introduce
> rebase, since we're already introducing a lot of concepts. Instead
> include a "Where to learn more" section with some pointers to where to
> continue learning.
> - GUIs (yes): Some readers wanted a suggestion for what GUI to use. It's
> very hard to suggest an appropriate GUI because there are so many and
> so many of them are not open source, but give a couple of suggestions
> of open source tools that seem to be popular with the community. Also
> mention that many non-open-source IDEs have built-in Git integrations
> for folks who are already using those tools who might not be aware,
> since they're a popular way to use Git.
>
> Co-Authored-By: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
> Signed-off-by: Marie Claire LeBlanc Flanagan <hello@marieflanagan.com>
> Signed-off-by: Julia Evans <julia@jvns.ca>
> ---
> doc: add tutorial on branches for beginners
>
> This was reviewed by 17 test readers who overall said it helped them
> understand branches. We addressed the feedback from the test readers to
> improve it before submitting it here.
>
> I think it would be good to add a little table of contents to
> gittutorial.adoc to match this one's TOC as well. I'm not sure what the
> best way to do that is since my understanding is that rebasing on the
> latest master causes problems.
>
> Changes in v2:
>
> * Use a $ for the commands for consistency (thanks to Junio)
> * Add more details in the example workflows to make sure they make
> sense logically (thanks to Junio)
> * Make sure the characters are alphabetized in the section order and in
> sentences. Rename Emilia -> Anita, Abdul -> Bruno, Betsy -> Carmen,
> Carmen and Daniela -> Daniela and Emilia. Keep the genders the same
> so we don't have to change all the pronouns. (thanks to Junio)
> * Deal with the poorly structured sections that Ben pointed at the end
> as follows:
> * Add a summary at the beginning to explain the overall structure
> * Move "3 ways to think about a branch" to the middle, right after
> creating the branch we're using as an example
> * Move the merge conflicts section to a note at the end of Step 13
> * Rename some of the headings to more clearly explain the structure
> (around "the step by step tutorial" and "Examples of using branches
> to collaborate")
> * Delete the "We normally start from main because if you create a
> branch called two..." explanation and instead just say that we want
> to keep branches independent (thanks to Ben)
> * One test reader said that in "3 ways to think about a branch", it was
> confusing to them than #1 and #3 were the same (just one commit). Add
> an extra commit to the add-fruits branch so that the branch has 2
> commits, to make it more clear what a branch with multiple commits on
> it looks like.
>
> Note: I used this script
> https://gist.github.com/jvns/bcd36fdd42952b9ec9a67ec139dba13e to create
> the example repository used in this document and to copy and paste the
> example output from. Not sure if we should store the contents of that
> script somewhere: it's very annoying to update the examples without it.
> I also realized there's an issue with that script where, because it
> hardcodes GIT_COMMITTER_DATE, all the commits happen at the same time,
> which makes the order of git log a bit weird. I manually adjusted Step
> 12 to account for that.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2307%2Fjvns%2Ftutorial-branches-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2307/jvns/tutorial-branches-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/2307
>
> Range-diff vs v1:
From the range-diff, I can see all my feedback was addressed (and I
like the new table of contents), along with some of what Junio
mentioned (I didn't look for "all", I'm not making a claim anything
was missed) and some typo-fixes. Very nice!
> +Step 8: Create another branch
> +-----------------------------
> +
> +Now create a second branch called `add-animals`. We're creating two
> +branches to show what the process of working on multiple changes at the
> +same time looks like.
> +
> +You'll usually want to start all new branches from the `main` branch
> +to keep your branches independent from each other. Right now
> +we're on the `add-fruits` branch, so we need to switch back to the
> +`main` branch:
> +
> +-----
> +$ git switch main
> +-----
> +
> +Then create a branch called `add-animals`.
> +
> +-----
> +$ git switch -c add-animals
> +-----
I assume we are choosing not to teach "git switch -c add-animals main" for some
reason here?
One reason I can imagine is that, depending on config like branch.autoSetupMerge
and the shape of the 2nd argument (main with config=inherit, origin/main with
default config, etc.), we end up configuring an upstream, and you said this
tutorial intentionally omits that. So while someone following the tutorial who
has not configured branch.autoSetupMerge away from the default would not have
any surprising upstream behavior from "git switch -c add-animals main" we cannot
control what will or won't happen, which might be confusing.
Is that what you were thinking, or something else?
(One reason I point it out is that I'm a personal fan of the ways Git helps me
type *less*, and I think the "multiple commands to achieve one logical thing"
contributes to the scary/complex reputation---OTOH, avoiding upstream stuff here
seems like the right way to go.)
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] doc: add tutorial on branches for beginners
2026-11-30 15:09 ` D. Ben Knoble
@ 2026-11-30 16:10 ` Julia Evans
2026-11-30 17:00 ` D. Ben Knoble
0 siblings, 1 reply; 15+ messages in thread
From: Julia Evans @ 2026-11-30 16:10 UTC (permalink / raw)
To: D. Ben Knoble, Julia Evans via GitGitGadget; +Cc: git, Patrick Steinhardt
>> +Step 8: Create another branch
>> +-----------------------------
>> +
>> +Now create a second branch called `add-animals`. We're creating two
>> +branches to show what the process of working on multiple changes at the
>> +same time looks like.
>> +
>> +You'll usually want to start all new branches from the `main` branch
>> +to keep your branches independent from each other. Right now
>> +we're on the `add-fruits` branch, so we need to switch back to the
>> +`main` branch:
>> +
>> +-----
>> +$ git switch main
>> +-----
>> +
>> +Then create a branch called `add-animals`.
>> +
>> +-----
>> +$ git switch -c add-animals
>> +-----
> I assume we are choosing not to teach "git switch -c add-animals main" for some
> reason here?
>
> One reason I can imagine is that, depending on config like branch.autoSetupMerge
> and the shape of the 2nd argument (main with config=inherit, origin/main with
> default config, etc.), we end up configuring an upstream, and you said this
> tutorial intentionally omits that. So while someone following the tutorial who
> has not configured branch.autoSetupMerge away from the default would not have
> any surprising upstream behavior from "git switch -c add-animals main" we cannot
> control what will or won't happen, which might be confusing.
>
> Is that what you were thinking, or something else?
I'd never heard of the syntax 'git switch -c add-animals main' until
right now! :)
My first reaction upon seeing that is that I'd be quite reluctant to use
it or recommend it because I very often hear from users that when a
command has 2 arguments that need to be specified in an order it's hard
for them to remember the order. For example with 'git checkout main --
file.txt' or 'ln -s file1.txt file2.txt'. Personally I don't think I
could remember the order of the arguments without looking it up (in 'git
switch branch1 branch2', what does each one mean?).
> (One reason I point it out is that I'm a personal fan of the ways Git helps me
> type *less*, and I think the "multiple commands to achieve one logical thing"
> contributes to the scary/complex reputation---OTOH, avoiding upstream stuff here
> seems like the right way to go.)
I'm not sure if "multiple commands to achieve one logical thing"
contributes to Git's scary/complex reputation. That could be true! It's
not something I've ever considered as a factor.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2] doc: add tutorial on branches for beginners
2026-11-30 16:10 ` Julia Evans
@ 2026-11-30 17:00 ` D. Ben Knoble
0 siblings, 0 replies; 15+ messages in thread
From: D. Ben Knoble @ 2026-11-30 17:00 UTC (permalink / raw)
To: Julia Evans; +Cc: Julia Evans via GitGitGadget, git, Patrick Steinhardt
On Mon, Nov 30, 2026 at 11:10 AM Julia Evans <julia@jvns.ca> wrote:
>
> >> +Step 8: Create another branch
> >> +-----------------------------
> >> +
> >> +Now create a second branch called `add-animals`. We're creating two
> >> +branches to show what the process of working on multiple changes at the
> >> +same time looks like.
> >> +
> >> +You'll usually want to start all new branches from the `main` branch
> >> +to keep your branches independent from each other. Right now
> >> +we're on the `add-fruits` branch, so we need to switch back to the
> >> +`main` branch:
> >> +
> >> +-----
> >> +$ git switch main
> >> +-----
> >> +
> >> +Then create a branch called `add-animals`.
> >> +
> >> +-----
> >> +$ git switch -c add-animals
> >> +-----
> > I assume we are choosing not to teach "git switch -c add-animals main" for some
> > reason here?
> >
> > One reason I can imagine is that, depending on config like branch.autoSetupMerge
> > and the shape of the 2nd argument (main with config=inherit, origin/main with
> > default config, etc.), we end up configuring an upstream, and you said this
> > tutorial intentionally omits that. So while someone following the tutorial who
> > has not configured branch.autoSetupMerge away from the default would not have
> > any surprising upstream behavior from "git switch -c add-animals main" we cannot
> > control what will or won't happen, which might be confusing.
> >
> > Is that what you were thinking, or something else?
>
> I'd never heard of the syntax 'git switch -c add-animals main' until
> right now! :)
Aha, I suspected that was an option, too :)
> My first reaction upon seeing that is that I'd be quite reluctant to use
> it or recommend it because I very often hear from users that when a
> command has 2 arguments that need to be specified in an order it's hard
> for them to remember the order. For example with 'git checkout main --
> file.txt' or 'ln -s file1.txt file2.txt'. Personally I don't think I
> could remember the order of the arguments without looking it up (in 'git
> switch branch1 branch2', what does each one mean?).
That's fair! The *only* form with 2 arguments is "switch
-c|--create|-C|--force-create", though, and the created branch always
comes after the "create" option.
I'm ok with not using this form here, even if I find it convenient.
Might be something we want to justify in the log message, which I
realize is already long ':D Then if a future editor wants to use
shorthands, at least there's something for them to find to consider
why it is this way now.
> > (One reason I point it out is that I'm a personal fan of the ways Git helps me
> > type *less*, and I think the "multiple commands to achieve one logical thing"
> > contributes to the scary/complex reputation---OTOH, avoiding upstream stuff here
> > seems like the right way to go.)
>
> I'm not sure if "multiple commands to achieve one logical thing"
> contributes to Git's scary/complex reputation. That could be true! It's
> not something I've ever considered as a factor.
Yeah, I dunno---it's speculation on my part. Maybe more precisely I
think it contributes to folks thinking of Git as "hard" (which it
certainly can be): they have to remember multiple commands to achieve
a single task, which we know from cognitive research adds additional
cognitive load. That load can either push other things out of our
brains or cause us to forget a step when we try to hold on to the
stuff we don't want to lose!
I suppose I'm a bit of an oddball though, in that I almost never do
anything other than
git switch -c <new-branch> origin
to create a new branch, though.
Anyway, if you decide not to change that, I'm personally happy with
this version (and you/Junio can add my Reviewed-by, if you like).
--
D. Ben Knoble
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-11-30 17:00 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 21:33 [PATCH] doc: add tutorial on branches for beginners Julia Evans via GitGitGadget
2026-11-09 21:56 ` Junio C Hamano
2026-11-09 22:01 ` Julia Evans
2026-11-09 22:11 ` Junio C Hamano
2026-11-10 14:31 ` Julia Evans
2026-11-18 12:43 ` Julia Evans
2026-11-23 18:05 ` D. Ben Knoble
2026-11-23 18:05 ` D. Ben Knoble
2026-11-24 15:56 ` Julia Evans
2026-11-24 19:04 ` Ben Knoble
2026-11-24 17:16 ` Junio C Hamano
2026-11-24 21:13 ` [PATCH v2] " Julia Evans via GitGitGadget
2026-11-30 15:09 ` D. Ben Knoble
2026-11-30 16:10 ` Julia Evans
2026-11-30 17:00 ` D. Ben Knoble
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox