Advanced Git Operations & Workflows
Git isn't just a version control tool โ it's the collaboration infrastructure of modern software development. Mastering advanced Git operations takes you from "knowing Git" to "mastering Git."
๐ฅ Vibe Prompt
"Create an advanced Git tutorial: Gitflow vs GitHub Flow comparison, interactive rebase in practice, when to use cherry-pick and stash, bisect debugging, and team commit message conventions."
Branching Strategies
GitHub Flow (Recommended for CD)
main โโโโ feat/a โโโโ merge โโโโ feat/b โโโโ merge
\ /
โโ commits โโโโโโโโโโโโโโ
Principles:
mainis always deployable- Branch from
mainfor new features - Branch naming:
feat/xxx,fix/xxx,chore/xxx - Merge via Pull Request
- Delete branch after merge
Gitflow (For Version Releases)
main โโโโ v1.0 โโโโ v1.1 โโโโ v2.0
\ / /
develop โโโโ feat โโโโ release โโโโ hotfix
Interactive Rebase
Interactive rebase lets you rewrite history โ clean up commits before pushing:
# Reorganize last 3 commits
git rebase -i HEAD~3
# You'll see:
pick abc123 feat: add login form
pick def456 fix: correct validation
pick 789ghi feat: add error handling
# Common commands:
# pick = keep this commit
# reword = change commit message
# squash = combine with previous commit
# fixup = combine and discard message
# drop = delete this commit
Cherry-Pick
Apply specific commits to the current branch:
# Pick one commit from another branch
git cherry-pick abc123
# Useful scenarios:
# - Apply a hotfix from main to release branch
# - Pick specific feature commits without full merge
Stash
Temporarily save unfinished work:
# Stash current changes
git stash
# Stash including untracked files
git stash -u
# View stash list
git stash list
# Apply stash (keep it)
git stash apply stash@{0}
# Apply and delete
git stash pop
Bisect (Binary Search Debugging)
Find which commit introduced a bug using binary search:
git bisect start
git bisect bad # current is bad
git bisect good v1.0 # v1.0 is good
# Git jumps to middle commit. Test and mark:
git bisect good # this commit is good
git bisect bad # this commit is bad
# After a few iterations, Git finds the first bad commit
git bisect reset
Commit Message Convention
<type>(<scope>): <subject>
<body>
<footer>
| Type | Purpose |
|------|---------|
| feat | New feature |
| fix | Bug fix |
| docs | Documentation |
| refactor | Code refactoring |
| test | Testing |
| chore | Maintenance |
Practice Exercise
๐ก Vibe Coding Practice: Ask AI to:
- Create an interactive script for proper Git workflow
- Create a pre-commit git hook for code quality
- Build an auto-changelog generator
- Simulate team workflow: branch โ develop โ rebase โ PR โ merge
Advanced Git Commands
| Command | Purpose |
|---------|--------|
| git rebase -i HEAD~5 | Interactive rebase: squash, reorder, edit commits |
| git cherry-pick abc123 | Apply a specific commit from another branch |
| git bisect start | Binary search to find the commit that introduced a bug |
| git blame file.js | See who last modified each line |
| git stash | Temporarily save uncommitted changes |
| git reflog | View reference log (recover lost commits) |
| git diff --staged | See staged changes |
| git log --oneline --graph | Visual commit history |
Interactive Rebase
# Squash the last 3 commits into one
git rebase -i HEAD~3
# In the editor:
pick abc123 First commit
squash def456 Second commit # squash into previous
squash ghi789 Third commit
# After save: only one commit with a new message
Git Bisect
# Find the commit that broke something
git bisect start
git bisect bad HEAD # Current version is broken
git bisect good v1.0 # v1.0 was working
# Git checks out a middle commit: is it good or bad?
git bisect good # or: git bisect bad
# Repeat until Git identifies the first bad commit
# Once found:
git bisect reset
Git Workflows
| Workflow | Description | Best For | |----------|-------------|----------| | GitHub Flow | Feature branch โ PR โ main | Simple, continuous deployment | | Git Flow | develop + feature + release + hotfix branches | Scheduled releases | | Trunk-Based | Short-lived branches, merge to main daily | CI/CD, large teams | | Forking | Contributors fork, submit PRs | Open source |
Summary
Advanced Git skills separate professional developers from beginners. Master rebasing, cherry-picking, bisecting, and the right workflow for your team.
Key takeaways:
- Interactive rebase: squash, reorder, and edit commits |
- Cherry-pick: apply specific commits to other branches |
- Bisect: binary search to find the bug-introducing commit |
- Reflog: recover lost commits (safety net) |
- GitHub Flow: simple, PR-based workflow |
- Git Flow: structured, release-oriented workflow |
- Trunk-based: fast CI/CD, short-lived branches |
What's Next: Terminal Mastery
The next chapter covers terminal mastery โ essential commands, shortcuts, and workflows.