| name | git-workflow-helper |
| description | Guide complex Git operations including interactive rebase, cherry-pick, conflict resolution, reflog recovery, and history rewriting with safety warnings and step-by-step guidance. |
Git Workflow Helper Agent
Description
Guide complex Git operations: interactive rebase, cherry-pick, conflict resolution, reflog recovery, history rewriting. Provide safety warnings, undo instructions, and step-by-step guidance for Kibana's Git workflow.
Trigger Patterns
- "rebase [branch] onto [base]"
- "cherry-pick [commit]"
- "resolve conflicts in [file]"
- "undo [git operation]"
- "fix commit history"
- "squash commits"
- "backport PR to [branch]"
- "recover lost commit"
Capabilities
1. Interactive Rebase
- Plan rebase strategy (squash, reword, reorder)
- Execute step-by-step with safety checks
- Handle conflicts during rebase
- Abort and recover if needed
2. Cherry-Pick Operations
- Select commits for cherry-pick
- Handle merge commits
- Resolve cherry-pick conflicts
- Batch cherry-pick with automation
3. Conflict Resolution
- Analyze conflict markers
- Suggest resolution strategy
- Validate resolution completeness
- Test after resolution
4. History Recovery
- Use reflog to find lost commits
- Recover from reset/rebase mistakes
- Restore deleted branches
- Undo force push (local)
5. Backporting
- Create backport branch
- Cherry-pick relevant commits
- Update backport labels
- Open backport PR
Interactive Rebase Guide
Planning Rebase
git log --oneline origin/main..HEAD
git rev-list --count origin/main..HEAD
git log --oneline --merges origin/main..HEAD
Decision Tree:
- 1-3 commits: Squash into 1 (clean history)
- 4-10 commits: Keep logical grouping (feature, fix, test)
- 10+ commits: Consider splitting into multiple PRs
- Has merges: Rebase will fail, use
git rebase -p or re-create branch
Executing Rebase
git rebase -i origin/main
git add <resolved-files>
git rebase --continue
git rebase --abort
Safety Checks:
- ✅ Working directory clean:
git status
- ✅ Remote up to date:
git fetch origin
- ✅ No merge commits:
git log --merges
- ✅ Branch backed up:
git branch backup-branch-name
Common Rebase Scenarios
Squash All Commits
git rebase -i HEAD~5
pick abc123 feat: initial work
squash def456 fix: review feedback
squash ghi789 fix: lint errors
squash jkl012 fix: type errors
squash mno345 chore: update tests
Reword Commit Messages
git rebase -i HEAD~3
reword abc123 fix: typo in commit message
pick def456 feat: feature X
pick ghi789 test: add tests
Reorder Commits
git rebase -i HEAD~3
Drop Commits
git rebase -i HEAD~3
pick abc123 feat: feature X
drop def456 wip: debugging code
pick ghi789 test: add tests
Rebase Conflicts
Understanding Conflict Markers
<<<<<<< HEAD (current - your base branch)
export class HttpServer {
private port = 5601;
=======
export class HttpServer {
private port = 9200;
>>>>>>> abc123 (incoming - your commit)
}
Resolution Strategy:
- Keep HEAD: Your base branch is correct
- Keep incoming: Your commit is correct
- Keep both: Merge manually (rare)
- Rewrite: Neither is correct, write new code
Resolving Conflicts
git status
git add src/core/server/http_server.ts
git rebase --continue
git rebase --abort
Auto-Resolution Strategies
git checkout --theirs src/core/server/http_server.ts
git add src/core/server/http_server.ts
git checkout --ours src/core/server/http_server.ts
git add src/core/server/http_server.ts
git mergetool
Cherry-Pick Guide
Single Commit Cherry-Pick
git log --oneline --grep="fix: bug Y"
git cherry-pick abc123
git add <resolved-files>
git cherry-pick --continue
git cherry-pick --abort
Batch Cherry-Pick
git cherry-pick abc123..ghi789
git cherry-pick abc123 def456 ghi789
git cherry-pick abc123 --edit
Cherry-Pick Merge Commit
git show --pretty=format:"%h %p" abc123
git cherry-pick -m 1 abc123
Cherry-Pick with Modification
git cherry-pick -n abc123
git commit -m "fix: adapted cherry-pick from main"
Conflict Resolution Strategies
Analysis Checklist
-
Conflict type:
- Content conflict (both modified same lines)
- Delete/modify conflict (one deleted, one modified)
- Rename conflict (both renamed differently)
-
Conflict scope:
- Small (few lines) → Manual resolution
- Large (entire file) → Consider rebasing approach
- Semantic (logic clash) → Requires deep understanding
-
Resolution strategy:
- Keep yours (your commit is correct)
- Keep theirs (base branch is correct)
- Merge both (combine changes)
- Rewrite (neither is correct)
Step-by-Step Resolution
Step 1: Identify Conflicts
git status | grep "both modified"
git diff --name-only --diff-filter=U
git diff src/core/server/http_server.ts
Step 2: Analyze Context
git log --oneline HEAD..origin/main -- src/core/server/http_server.ts
git log --oneline origin/main..HEAD -- src/core/server/http_server.ts
git show HEAD:src/core/server/http_server.ts
git show origin/main:src/core/server/http_server.ts
Step 3: Resolve
git checkout --ours src/core/server/http_server.ts
git checkout --theirs src/core/server/http_server.ts
git mergetool
Step 4: Validate
git add src/core/server/http_server.ts
grep -r "<<<<<<< \|======= \|>>>>>>>" src/
yarn test:type_check --project src/core/tsconfig.json
node scripts/eslint src/core/server/http_server.ts
yarn test:jest src/core/server/http_server.test.ts
Step 5: Continue Operation
git rebase --continue
git cherry-pick --continue
git commit
History Recovery (Reflog)
Find Lost Commits
git reflog -30
git cherry-pick def456
git reset --hard def456
Recover from Reset
git reflog | grep "reset"
git reset --hard def456
git checkout -b recovery-branch def456
Recover Deleted Branch
git reflog | grep "my-feature"
git checkout -b my-feature abc123
Recover from Rebase Gone Wrong
git reflog | grep "rebase"
git reset --hard abc123
git branch backup-before-rebase abc123
Backporting Guide
Create Backport PR
Automatic Backport (Kibana Specific)
Manual Backport
git fetch origin 8.x
git checkout -b backport-12345-to-8.x origin/8.x
git log --oneline origin/main ^origin/8.x | grep "#12345"
git cherry-pick abc123 def456
git push origin backport-12345-to-8.x
gh pr create \
--base 8.x \
--head backport-12345-to-8.x \
--title "[8.x] Fix: bug Y (#12345)" \
--body "Backport of #12345 to 8.x"
Backport Validation
node scripts/check_changes.ts
git merge-base origin/8.x HEAD
Undo Operations
Undo Last Commit (Keep Changes)
git reset --soft HEAD~1
Undo Last Commit (Discard Changes)
git reset --hard HEAD~1
Undo Pushed Commit (Force Push)
git reset --hard HEAD~1
git push --force-with-lease origin my-branch
Undo Merge
git reset --hard HEAD~1
git revert -m 1 abc123
Undo Rebase (Before Push)
git reflog | grep "rebase"
git reset --hard abc123
Undo Cherry-Pick
git cherry-pick --abort
git reset --hard HEAD~1
Safety Protocols
Pre-Operation Checks
git status
git fetch origin
git branch backup-$(date +%Y%m%d-%H%M%S)
git branch -vv
Force Push Safety
git push --force-with-lease origin my-branch
git fetch origin
git rebase origin/my-branch
git push --force-with-lease origin my-branch
Branch Protection Rules
gh api repos/elastic/kibana/branches/main/protection
Integration with Other Skills
With @buildkite-ci-debugger
@buildkite-ci-debugger --build <url>
With @kibana-precommit-checks
@kibana-precommit-checks
With @migration-planner
@migration-planner track migration progress
@git-workflow-helper backport PR
Examples
Example 1: Squash Commits Before Merge
User: "squash my last 5 commits into 1"
Agent Actions:
git log --oneline HEAD~5..HEAD
git rebase -i HEAD~5
git log --oneline HEAD~1..HEAD
Output: Single clean commit ready for merge.
Example 2: Resolve Rebase Conflicts
User: "resolve conflicts in http_server.ts during rebase"
Agent Actions:
git diff src/core/server/http_server.ts
git log --oneline origin/main..HEAD -- src/core/server/http_server.ts
yarn test:type_check --project src/core/tsconfig.json
yarn test:jest src/core/server/http_server.test.ts
git add src/core/server/http_server.ts
git rebase --continue
Output: Conflict resolved, rebase continues.
Example 3: Recover Lost Commit
User: "undo my reset, I lost my commit"
Agent Actions:
git reflog -30
git cherry-pick def456
git reset --hard def456
git checkout -b recovery-feature-x def456
git log --oneline HEAD~1..HEAD
Output: Commit recovered, work safe.
Example 4: Backport Fix to 8.x
User: "backport PR #12345 to 8.x"
Agent Actions:
git fetch origin 8.x
git checkout -b backport-12345-to-8.x origin/8.x
gh pr view 12345 --json commits --jq '.commits[].oid'
git cherry-pick abc123 def456
git push origin backport-12345-to-8.x
gh pr create \
--base 8.x \
--head backport-12345-to-8.x \
--title "[8.x] Fix: security issue (#12345)" \
--body "Backport of #12345 to 8.x"
Output: Backport PR created and validated.
Troubleshooting
Rebase Failed: "Cannot rebase merge commits"
git log --oneline --merges origin/main..HEAD
git checkout main
git pull origin main
git checkout -b my-branch-clean
git cherry-pick <commit1> <commit2> <commit3>
git rebase -p origin/main
Cherry-Pick Failed: "Empty commit"
git cherry-pick --skip
git cherry-pick --abort
git diff origin/main..HEAD
Conflicts After Every Commit During Rebase
git rebase --abort
git checkout main
git pull origin main
git checkout -b my-branch-fresh
git cherry-pick <commits>
Force Push Rejected
git push --force-with-lease origin my-branch
git fetch origin
git rebase origin/my-branch
git push --force-with-lease origin my-branch
Lost Work After Reset
git reflog -30
git reset --hard <commit-before-reset>
Best Practices
Rebase
- ✅ Rebase personal branches before merging
- ✅ Squash fixup commits (lint, type errors)
- ✅ Keep logical commit grouping
- ✅ Backup branch before rebase
- ❌ Don't rebase shared branches (main, 8.x)
- ❌ Don't rebase if branch has merge commits
Cherry-Pick
- ✅ Cherry-pick for backports
- ✅ Cherry-pick for selective fixes
- ✅ Use --edit to update commit message
- ❌ Don't cherry-pick large ranges (use merge)
- ❌ Don't cherry-pick merge commits (use -m)
Conflict Resolution
- ✅ Understand context before resolving
- ✅ Test after resolution (type + lint + test)
- ✅ Ask for help if semantic conflict
- ❌ Don't blindly accept one side
- ❌ Don't leave conflict markers
Force Push
- ✅ Use --force-with-lease (never --force)
- ✅ Only force push personal branches
- ✅ Warn collaborators before force push
- ❌ Never force push main/8.x
- ❌ Don't force push without backup
Notes
- Git is forgiving (reflog saves everything for 90 days)
- When in doubt, create backup branch first
- Force push with --force-with-lease, never --force
- Kibana bot handles backports automatically (label PR)
- Complex rebases: consider recreating branch instead