git branch
The command that lists, creates, renames and deletes branches.
git branch -D deletes unmerged work; it survives only in the reflog until it expires.
In more detail
git branch feature creates a branch at the current commit without switching to it. -v shows each branch's latest commit and -r lists remote-tracking branches. -m renames, -d deletes a branch only if its work is merged, and -D deletes it regardless.
Examples
git branch -m feature notes-tidygit branch recovered d4e5f6gRelated terms
- branch — In Git, a movable name for one commit; committing on the branch moves the name forward to the new commit.
- git switch — The command that moves you to another branch, updating HEAD and the working tree to match; -c creates the branch first.
- remote-tracking branch — A local, read-only record of where a branch on a remote pointed the last time you talked to it, such as origin/main.
Taught in
- A Branch Is A Moving Pointer — Advanced Git Internals & Distributed Workflows
- HEAD, And Why Detached HEAD Is Not An Error — Advanced Git Internals & Distributed Workflows
- Merging: Fast Forward Or A Merge Commit — Advanced Git Internals & Distributed Workflows
- What A Remote Actually Is — Advanced Git Internals & Distributed Workflows
- Cherry Picking, Reflog, And Getting Work Back — Advanced Git Internals & Distributed Workflows