Merge a branch
A merge integrates commits from one branch into the branch you currently have checked out. Always stand on the destination branch.
Merge locally
# Move to the destination branch.
git switch main
# Update it before merging when it tracks a remote.
git pull --ff-only origin main
# Integrate the feature branch.
git merge feature/<short-description>
If the feature branch has no commits that are unique from main, Git reports that it is already up to date. If it is directly ahead, Git may perform a fast-forward merge.
Resolve a conflict
If Git reports conflicts:
# See conflicted files.
git status
# After editing and resolving each file.
git add <resolved-file>
git commit
To abandon the merge before committing:
Review the result
Run git diff HEAD^ HEAD or git log --oneline --decorate -n 5 after a successful merge to verify the resulting history.
Delete the merged branch
Only delete the remote branch after confirming the pull request or local merge is complete.