In trunk-based development, developers typically work on small changes directly in the main branch or on short-lived feature branches. The goal is to integrate changes to the main branch as frequently as possible to avoid large merge conflicts and integration issues.
Here's the general workflow:
- Update your local main branch with the latest changes from the remote main branch:
git checkout main
git pull origin main
- Create a new feature branch from the updated main branch:
git checkout -b feature_branch
- Make your changes in the feature branch and commit them:
git add .
git commit -m "Your commit message"
- Regularly pull the latest changes from the main branch into your feature branch to stay up-to-date:
git pull origin main
- Once your feature is complete, push your feature branch to the remote repository:
git push origin feature_branch
-
Create a pull request to merge your feature branch into the main branch.
-
After the pull request is reviewed and all tests pass, merge the pull request.
-
Delete the feature branch after it's merged.
This approach minimizes the time that the feature branch is divergent from the main branch, reducing the likelihood of merge conflicts.
When you push changes to a branch that has an open pull request, the pull request gets updated automatically with those changes.
This is because a pull request is tied to a branch, not to a specific commit. Any new commits pushed to the associated branch will automatically be included in the open pull request. This allows you to make updates or corrections based on feedback during code review, resolve merge conflicts, or add additional features or fixes before the pull request is merged.