0
0
Gitdevops~30 mins

Golden rule of rebasing (never rebase public) in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Golden Rule of Rebasing (Never Rebase Public)
📖 Scenario: You are working on a shared project with your team using Git. You want to understand why rebasing commits that have already been shared with others (public commits) can cause problems.This project will guide you through creating a simple Git commit history, marking commits as public or private, and practicing safe rebasing only on private commits.
🎯 Goal: Learn how to identify public and private commits in Git and practice rebasing only private commits to avoid disrupting your team's work.
📋 What You'll Learn
Create a list of commits with their public/private status
Add a variable to mark the current branch's public commit hash
Write a function to rebase only commits that are not public
Print the list of commits after safe rebasing
💡 Why This Matters
🌍 Real World
In real software projects, developers share commits with teammates. Rebasing commits that others already have can cause conflicts and confusion. This project shows how to avoid rebasing public commits.
💼 Career
Understanding safe rebasing is essential for collaborative software development roles like DevOps engineers, software developers, and release managers to maintain clean and stable project history.
Progress0 / 4 steps
1
Create a list of commits with public/private status
Create a list called commits with these exact dictionaries representing commits: {'hash': 'a1b2c3', 'message': 'Initial commit', 'public': true}, {'hash': 'd4e5f6', 'message': 'Add feature', 'public': false}, {'hash': 'g7h8i9', 'message': 'Fix bug', 'public': false}.
Git
Need a hint?

Use a list of dictionaries. Each dictionary must have keys: 'hash', 'message', and 'public' with exact values.

2
Mark the current branch's public commit hash
Create a variable called public_commit_hash and set it to the string 'a1b2c3' to mark the last public commit.
Git
Need a hint?

Assign the exact string 'a1b2c3' to the variable public_commit_hash.

3
Write a function to rebase only private commits
Write a function called safe_rebase that takes the commits list and public_commit_hash string as parameters. It should return a new list with only commits after the public commit (where commit['public'] is false). Use a for loop with variable commit to iterate over commits.
Git
Need a hint?

Use a flag found_public to start collecting commits only after the public commit hash is found.

4
Print the list of commits after safe rebasing
Call the safe_rebase function with commits and public_commit_hash. Store the result in rebased_commits. Then print rebased_commits.
Git
Need a hint?

Call safe_rebase(commits, public_commit_hash), assign to rebased_commits, then print it.