Journal Feed

Advanced Git Workflow: Rebase, Cherry-Pick & CI/CD

Advanced Git & GitHub Workflow: Interactive Rebase and CI/CD

Git is the foundational version control system powering modern software development. Yet, many development teams struggle with messy, unreadable commit histories, tedious merge conflicts, and manual release pipelines.

Mastering advanced Git capabilities—such as interactive rebasing, cherry-picking specific bug fixes, bisecting regression bugs, and setting up automated GitHub Actions CI/CD pipelines—elevates your engineering workflow to an enterprise standard.

In this technical guide, you will learn how to maintain a clean linear Git history, automate pull request checks, and deploy software releases reliably.

Key Takeaways & Summary

  • Clean up messy feature branch commit histories using `git rebase -i`.
  • Isolate and apply single commits across branches using `git cherry-pick`.
  • Locate hidden software regressions automatically using `git bisect` binary search.
  • Build automated linting, testing, and deployment workflows using GitHub Actions.

1. Cleaning History with Interactive Rebase

When developing complex features, your local branch often accumulates dozens of messy commits like 'fix typo' or 'wip test'. Before opening a Pull Request, clean your commit tree using interactive rebase:

# Start interactive rebase for the last 5 commits
git rebase -i HEAD~5

# Commands inside rebase editor:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = stop for amending
# s, squash = meld into previous commit and combine messages
# fixup = like squash, but discard this commit's message

Golden Rule of Rebasing

Never rebase shared public branches (like main or release). Only rebase local feature branches before merging them into main to preserve shared history integrity.

2. Selective Commit Extraction: Git Cherry-Pick

Imagine a scenario where a critical hotfix was accidentally committed to an unreleased experimental feature branch. Instead of merging the entire feature branch, extract only the specific fix commit using cherry-pick:

# Switch to target production branch
git checkout main

# Apply single specific commit by hash
git cherry-pick a1b2c3d4

# Push clean fix directly to remote main
git push origin main

3. Automated Bug Hunting with Git Bisect

When a bug appears in production and you don't know which of the last 200 commits introduced it, git bisect uses binary search to find the offending commit in seconds:

git bisect start
git bisect bad HEAD             # Current version has the bug
git bisect good v1.2.0          # Last known working release tag

# Git automatically checks out intermediate commits for testing
# Mark each step as 'git bisect good' or 'git bisect bad'
# Finish bisect session
git bisect reset

4. GitHub Actions CI/CD Pipeline Integration

Automate testing and code quality checks on every Pull Request by creating a .github/workflows/ci.yml file:

CI/CD Pipeline StageAction TriggeredTarget Outcome
Linting & FormattingRuns ESLint / Black formatterRejects non-compliant code formatting
Unit & Integration TestsExecutes PyTest / Jest test suitePrevents merging broken code
Build VerificationCompiles Docker image / Production bundleValidates artifact creation
Automated DeploymentDeploys to Staging / Production via SSH/K8sHands-free continuous delivery

Frequently Asked Questions (FAQ)

Q: What is the difference between Git Merge and Git Rebase?
A: Git Merge creates a new non-destructive merge commit preserving full historical context. Git Rebase rewrites commit history by moving your feature branch commits onto the tip of the target branch, maintaining a clean linear line.
Q: How do I safely undo a bad Git rebase?
A: Use `git reflog` to view your local repository actions history, locate the SHA hash right before starting the rebase, and run `git reset --hard `.
Q: Are GitHub Actions free for open-source repositories?
A: Yes. GitHub Actions provides unlimited free build minutes for public repositories and 2,000 free monthly build minutes for private accounts.

Master Advanced Developer Tools!

Download our comprehensive Git Workflow Cheat Sheet featuring interactive rebase diagrams, cherry-pick commands, and GitHub Actions templates.

Download Git Workflow Guide
ZS

Zaheer Shaikh

SEO Manager, Tech Enthusiast & Digital Content Strategist. Specializing in search engine growth, clean web design, and digital publishing.