Development Workflow

Using Git Branches in PHP Projects

Use Git branches to isolate features, bug fixes, and releases while keeping the main PHP application stable.

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:

  1. Open each conflicted file.
  2. Decide which changes should remain.
  3. Remove conflict markers.
  4. Run tests and inspect the diff.
  5. 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.