creating, switching, and deleting branches
git checkout -b feature/my-thingcreates a new branch and switches to it in one step. the classic.
git branchlists all local branches. git branch -a includes remotes too.
git branch -d feature/my-thingdeletes a branch. use -D if git complains that it's not fully merged and you're sure you want it gone.
git switch feature/my-thingnewer way to switch branches. git switch -c feature/my-thing creates and switches, same as checkout -b. either works, switch is just cleaner.
never commit directly to main. always branch first, do your work, then PR.
# wrong — don't do this
git checkout main
git add .
git commit -m "my feature"
# right
git checkout -b feat/my-thing
git add .
git commit -m "my feature"
git push origin feat/my-thing
# then open PRif you accidentally commit to main locally, branch off before pushing:
git checkout -b feat/my-thing # branch from current state
git checkout main
git reset --hard origin/main # reset main back to remoteyour commits are now safely on the feature branch, main is clean.