Why use branches?
A branch lets you work on a change without immediately modifying the main development line. This is useful for new features, maintenance, and urgent fixes.
Create a feature branch
git switch -c feature/article-search
Make and commit your changes:
git add .
git commit -m "Add article search"
Merge a completed branch
Switch to the target branch and merge:
git switch main
git merge --no-ff feature/article-search
Run the test suite and review the result before releasing.
Handle conflicts
If Git reports a merge conflict:
- Open each conflicted file.
- Decide which changes should remain.
- Remove conflict markers.
- Run tests and inspect the diff.
- Stage the resolved files and complete the merge.
git add path/to/resolved-file.php
git commit
Keep branches manageable
Use descriptive names such as feature/user-profile or fix/login-validation. Delete merged branches when they are no longer needed, and avoid allowing long-lived branches to drift far from the main branch.