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
| Command | What it does |
|---|---|
git branch | List 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 -vv | Show 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.
Soalan Lazim
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
Git Config Essentials
Set identity, defaults, and aliases for Git on a new machine.
Git Clone and Init
Start a repo from scratch or copy a remote repository locally.
Git Add and Commit
Stage changes and record them as commits with clear messages.
Git Switch and Checkout
Move between branches and restore files without losing work.