Branches
A branch in git is a movable label on a commit; switching branches rewrites your working files to match a different line of history. On the command line the switch is one command and a wall of possible errors. Here it is a panel, a selection and the Space bar. The outcome: you can move between branches, carry your uncommitted work with you (or discover why you cannot), create a branch in the same motion as checking it out, and meet the error that guards the branch you are already on.
The Branches panel
Press 3 — the digit jumps straight
to panel 3, Local branches. Its hint
bar reads:
Checkout: <space> | New branch: n | Delete: d | Rebase: r | Reset: g | Upstream: u | …
The list is sorted with purpose: the
current branch first, marked *, then
the others by how recently each moved —
the small time beside a name ("6s", "1m")
is how long since that branch last
gained a commit. While the panel is
focused, the main panel shows the
selected branch's log, so you can read
where a branch is before you go there.
Checking out
Select add-autumn-walk and press
Space (transcript
lazygit-lab/transcripts/t04-branches.txt).
In one motion:
- The command log records
git checkout add-autumn-walk— the real command, unchanged. - The Status panel now reads
fixture → add-autumn-walk. - The branch list re-sorts: the branch you are on goes to the top.
- The Commits panel shows this branch's
history — five commits now, including
the two autumn-walk commits
maindoes not have. - The Files panel still shows your three
uncommitted changes. Uncommitted work
travels with you when you switch
branches, exactly as it does with
git checkout, provided the switch does not overwrite it. If it would, git refuses, and lazygit shows you git's refusal — the remedy is chapter 1's rule: commit the work, or stash it (chapter 9), then travel.
Press Space on the branch you are already on and the program stops you with a plain error box: "You have already checked out this branch." It is a small moment, but a telling one — lazygit prefers a clear sentence to a silent nothing, and several of this guide's transcripts are of its sentences.
Check: the prompt's own git branch
--show-current, after quitting, agrees
with the Status panel. In the lab it did.
Creating a branch
Press n. A prompt asks for the new
branch's name — nothing more. The branch
is created from the branch you had
selected, and checked out in the same
motion. The lab, with main selected,
named one winter-notes, and the
command log kept the full truth:
git checkout -b winter-notes refs/heads/main --no-track
Two details in that line are worth
reading once. It is one command, not two:
creation and checkout together, as
git checkout -b has always done. And
--no-track means the new branch does
not automatically track the branch it
came from — it starts life unattached to
any upstream, which is the honest default
for a local line of work (upstreams are
chapter 12's subject).
To branch from a commit rather than a
branch, the Commits panel offers the
same creation starting from the selected
commit. The lab created its branch from
a branch; the from-a-commit door is the
documented twin, filed as such in
criteria.md.
Enter on a branch
One more key before the chapter ends, because it changes how you explore: Enter on a branch replaces the Branches panel with that branch's list of commits — a sub-view, titled Commits (winter-notes) when the lab did it, with its own hint bar (chapter 7 climbs the rest of this staircase: Enter again, on a commit, lists the files that commit touched). Esc climbs back out. The lab discovered these sub-views while aiming at something else entirely, which is the most lazygit way to learn anything: the program is built to be poked, and Esc is nearly always the way back.
Deleting, briefly
The hint bar's d deletes the selected
branch, behind a confirmation; a branch
with commits no other branch contains
gets a sterner warning and a force
option, exactly as git branch -d and
-D divide the world. The lab did not
execute a deletion — its attempt wandered
into the sub-views above instead, a
failure criteria.md records plainly —
so this paragraph is the documentation's
account, labelled as such. The habit it
teaches is safe either way: before
deleting, Enter into the branch and read
its commits. If they exist nowhere else,
deleting the label is the one everyday
operation that can strand real work —
and chapter 8's reflog, not the bin, is
where stranded commits are recovered
from.