Skip to content

Instantly share code, notes, and snippets.

@tarasowski
Created February 6, 2024 06:38
Show Gist options
  • Select an option

  • Save tarasowski/605aea89ef0d5bc965daa76db556db80 to your computer and use it in GitHub Desktop.

Select an option

Save tarasowski/605aea89ef0d5bc965daa76db556db80 to your computer and use it in GitHub Desktop.
Trunk-based development typical workflow

In trunk-based development, all developers work on a single branch called 'trunk' or 'main'. The goal is to avoid long-lived feature branches, merge conflicts, and integration hell. Here's a typical workflow:

  1. Update from Main: Developers start by updating their local copy of the main branch to the latest version. This is done using the git pull command.

    git pull origin main
  2. Create a Short-Lived Feature Branch: Although all work is done on the main branch, developers create short-lived feature branches to isolate their changes. This is done using the git checkout -b command.

    git checkout -b feature_branch
  3. Make Changes: Developers make their changes on the feature branch. This could involve editing files, creating new files, or deleting files.

  4. Stage Changes: Once they're happy with their changes, developers stage these changes using the git add command.

    git add .
  5. Commit Changes: After staging their changes, developers commit these changes using the git commit command.

    git commit -m "Commit message"
  6. Pull Latest Changes from Main: Before pushing their changes, developers pull the latest changes from the main branch again. This is to ensure that they're not going to overwrite any recent changes.

    git pull origin main
  7. Resolve Conflicts: If there are any conflicts between their changes and the changes on the main branch, developers resolve these conflicts.

  8. Push Changes to Feature Branch: Developers push their changes to the remote feature branch using the git push command.

    git push origin feature_branch
  9. Create a Pull Request: Developers create a pull request to merge their feature branch into the main branch. This is usually done through the interface of the Git hosting service (like GitHub, GitLab, Bitbucket).

  10. Code Review: Other developers review the changes and provide feedback.

  11. Merge Changes into Main: Once the changes have been approved, they're merged into the main branch. The feature branch can then be deleted.

  12. Deploy: Changes on the main branch are regularly deployed to production.

This workflow encourages frequent commits, short-lived feature branches, and regular integration with the main branch, which leads to easier conflict resolution and more stable code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment