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.
Both developers are technically correct in their own ways, but their approaches serve different purposes.
The developer who didn't pull the latest changes from
origin/main
into their branch is working in isolation. This can be beneficial if they want to avoid being interrupted by changes from others. However, this approach might lead to complex merge conflicts later when they try to merge their changes intomain
.The developer who did pull the latest changes from
origin/main
into their branch is keeping their branch up-to-date with the latest changes. This can help identify and resolve merge conflicts sooner rather than later. It also ensures that the work they're doing is compatible with the latest state of themain
branch.In general, it's a good practice to regularly pull the latest changes from the main branch into your feature branch. This helps keep your branch up-to-date and can make the eventual merge back into
main
smoother. However, the right approach can depend on the specific circumstances of your project and team.