Git Workflows and Developer Best PracticesLesson 6.1
How to use Git branches for feature development
git branch, git checkout -b, git switch, branch naming conventions, git merge, git branch -d, fast-forward vs merge commit, HEAD pointer
Git Branching for Features
Branches let you work on a feature without touching the main codebase. You create a branch, commit your work, and merge when ready. This is the foundation of every professional Git workflow.
Creating and switching branches
git branch feature/login
git checkout feature/login
# Or in one command:
git switch -c feature/loginBranch naming conventions
Use lowercase with slashes: feature/, fix/, chore/, docs/. Examples: feature/user-auth, fix/null-pointer-crash.
Merging a branch into main
git switch main
git merge feature/loginIf main has no new commits since the branch was created, Git does a fast-forward merge (no merge commit). If both branches have diverged, Git creates a merge commit.
Deleting merged branches
git branch -d feature/login # safe delete (must be merged)
git branch -D feature/login # force deleteViewing all branches
git branch
git branch -r
git branch -a