~/
hackweb.dev
Branching
Quiz
⌘K
...
~/
/tutorials
/git/git-branches/edit
~ Contribute
Suggest a correction or improvement. The author reviews it before it goes live.
Loading...
Comment
0 / 300
Typo
Grammar
Broken link
Clarify
Code
en/tutorials/git/7git-branches
Write
Preview
Diff
# Branching Branches let you develop features, fix bugs, or experiment in isolation without affecting the `main` line. ## Creating a Branch ```bash git branch feature ``` This creates a new branch called `feature` but stays on your current branch. ## Switching Branches ```bash git switch feature ``` Moves you to the `feature` branch. Your working directory updates to match. ## Create and Switch in One Step ```bash git switch -c feature ``` Creates the branch and switches to it immediately — the most common workflow. ## Listing Branches ```bash git branch # local branches git branch -a # includes remote branches ``` The current branch is marked with `*`. ## Deleting a Branch ```bash git branch -d feature ``` Safely deletes after merging. Use `-D` to force delete unmerged branches. ## Best Practices - Use short, descriptive branch names (`feature/auth`, `fix/login-bug`) - Keep `main` always deployable - Delete branches after merging - One feature per branch ## Common Mistakes - Forgetting to switch branches before editing files - Creating branches from the wrong starting point - Not deleting stale branches - Working directly on `main` for new features
No changes yet
Reset to original
Submit suggestion
cancel