Git Branch Basics

Create, list, rename, and delete branches for parallel work.

  • git branch
  • git switch
  • rename branch
  • delete branch
  • create branch

Git Branch Basics

Create, list, rename, and delete branches for parallel work.

Commands

CommandWhat it does
git branchList local branches (* marks current)
git branch <name>Create a branch at current HEAD
git switch -c <name>Create and switch to a branch
git branch -m <old> <new>Rename a branch
git branch -d <name>Delete a merged branch (-D forces)
git branch -vvShow branches with upstream tracking info

Example

git switch -c feature/search
git branch -vv
git branch -d feature/search

FAQ

switch vs checkout?

switch is the modern branch-only command; checkout also restores files, which is riskier.

How do I delete a remote branch?

Use git push origin --delete <name>; local -d alone leaves the remote branch intact.

Частые вопросы

switch vs checkout?
switch is the modern branch-only command; checkout also restores files, which is riskier.
How do I delete a remote branch?
Use git push origin --delete <name>; local -d alone leaves the remote branch intact.

Git