Create, rename, and delete branches, merge them back together, and resolve merge conflicts when Git can't decide for you.
Why: branches let you work on something new without touching main until you are ready to merge it back.
Create a branch and switch to it in one step
git switch -c "new-branch-name"List all branches (current one is marked with *)
git branchList all branches (local and remote)
git branch -aSwitch back to main
git switch mainRename a branch
git branch -m "old-branch-name" "new-branch-name"Delete a branch that has been merged
git branch -d "branch-name"Force-delete a branch with unmerged commits
git branch -D "branch-name"Delete a branch from your remote repository server
git push origin --delete "branch-name"Why: merging brings the commits from one branch into another, combining the two histories.
git merge --no-ff "branch-name"Note: a conflict means Git can't tell which version of a line is correct — you decide, then tell Git you're done.
git merge --no-ff "branch-name"See which files need attention
git status -sLook for the markers: <<<<<<< HEAD your version ======= their version >>>>>>> feature/login-form Edit the file to keep what's correct, then remove the markers.
git add "file"Complete the merge
git commitOr abandon the merge entirely and go back to before it started
git merge --abort