Skip to content

Instantly share code, notes, and snippets.

@tarasowski
Created February 6, 2024 07:01
Show Gist options
  • Save tarasowski/56c90fde8d0626222e00c3f256e1225f to your computer and use it in GitHub Desktop.
Save tarasowski/56c90fde8d0626222e00c3f256e1225f to your computer and use it in GitHub Desktop.
Case study trunk-based development

Sure, here's a simple simulation of how a trunk-based development might work with 5 students working on a simple Python application. We'll assume that each student is working on a different feature of the application.

  1. Initial Setup: The instructor (or one of the students) creates a new repository on GitHub for the Python application. This repository contains the main branch (trunk).

  2. Clone the Repository: Each student clones the repository to their local machine.

    git clone https://github.com/instructor/python-app.git
  3. Create a Short-Lived Feature Branch: Each student creates a new branch for their feature from the main branch.

    git checkout -b feature-1  # Each student should replace "feature-1" with the name of their feature
  4. Develop the Feature: Each student writes the code for their feature. They commit their changes regularly and push them to their feature branch on GitHub.

    git add .
    git commit -m "Progress on feature"
    git push origin feature-1  # Replace "feature-1" with the name of the feature
  5. Pull Request: Once a student has finished their feature, they create a pull request on GitHub. This is a request to merge their feature branch into the main branch.

  6. Code Review: The instructor (or other students) review the code in the pull request. They may suggest changes or improvements.

  7. Merge the Feature: Once the code has been reviewed and approved, it's merged into the main branch. The feature branch can then be deleted.

  8. Update the Local Main Branch: After a feature has been merged into the main branch, all students should update their local main branch to get the latest changes.

    git checkout main
    git pull origin main
  9. Repeat: Steps 3-8 are repeated for each new feature.

This process ensures that all changes are integrated into the main branch frequently and that the main branch always contains a working version of the application. It also encourages collaboration and code review, as all changes are reviewed before they're merged into the main branch.

@tarasowski
Copy link
Author

tarasowski commented Feb 6, 2024

To roll back changes from the main branch (also known as trunk) in Git, you can use the git revert command. This command creates a new commit that undoes the changes made in a specific commit.

Here's a step-by-step guide:

  1. First, you need to find the commit hash of the commit you want to revert. You can do this by using the git log command, which will display a list of all the commits. The commit hash is the long string of numbers and letters next to each commit.

  2. Once you have the commit hash, you can use the git revert command followed by the commit hash to create a new commit that undoes the changes made in that commit.

Here's how you can do it:

# Display the commit log
git log

# The output will look something like this:
# commit 5f57d5b1b3e7a9a378824fdd73a9f6c5a9909632
# Author: Your Name <your.email@example.com>
# Date:   Mon Sep 24 15:31:10 2018 -0700
# 
#     Your commit message

# Now, to revert the changes made in that commit, you would do:
git revert 5f57d5b1b3e7a9a378824fdd73a9f6c5a9909632

# This will create a new commit that undoes the changes made in the specified commit.
# Now, push the new commit to the remote repository
git push origin main

Remember to replace 5f57d5b1b3e7a9a378824fdd73a9f6c5a9909632 with the hash of the commit you want to revert.

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