Git Workflow Best Practices
Tool Availability
All git operations use run_command with standard git CLI commands. The changelist_shelve tool
provides IDE-native IntelliJ changelist shelving.
run_command blocks destructive remote operations (push, fetch, pull, clone, reset --hard, clean -f,
rebase, merge, and any command referencing origin/ or upstream/).
Before Any Git Operation
- Use
run_command("git status")to understand current state (branch, uncommitted changes) - Use
run_command("git branch -a")to see available branches — NEVER assume "main" or "master" exists
Comparing Branches
To check if changes exist between branches:
run_command("git branch -a")— find the actual branch namesrun_command("git merge-base <ref1> <ref2>")— find divergence pointrun_command("git diff <target-branch>")— see actual differences- For a specific file:
run_command("git diff <target-branch> -- src/main/Foo.kt")
NEVER use run_command("git diff origin/...") — this references remote refs which are blocked.
Checking if a Ticket's Changes Are on a Branch
run_command("git log --oneline -30")— search commit messages for the ticket keyrun_command("git show <hash>")— view the specific commit's changesrun_command("git diff <base-branch> -- <changed-file>")— compare with base
Reviewing File History
run_command("git log --oneline --follow -- src/main/Foo.kt")— all commits that touched this file (follows renames)run_command("git blame src/main/Foo.kt -L 40,60")— who changed specific linesrun_command("git show HEAD~5:src/main/Foo.kt")— file content 5 commits ago
Viewing a File at a Different Branch
Use run_command("git show <branch>:src/main/Foo.kt") — NOT run_command("git checkout <branch>").
NEVER switch branches. NEVER checkout. Read file content at any ref without modifying working tree.
Understanding Branch Divergence
run_command("git merge-base feature-branch develop")— find common ancestorrun_command("git log --oneline develop -20")— recent commits on the target branchrun_command("git diff develop")— full diff between current branch and target
Shelving Changes (IntelliJ Changelists)
Use changelist_shelve to shelve IntelliJ changelists (IDE-native, not git stash):
- Shelve uncommitted changes before switching context
- Unshelve when returning to the task
- Prefer this over
git stashwhen working inside IntelliJ
PR-Related Tasks
For PR-related git tasks, use Bitbucket tools (deferred — activate via tool_search first):
bitbucket_pr(action="get_pr_diff")for diffsbitbucket_pr(action="get_pr_changes")for changed filesbitbucket_pr(action="get_pr_commits")for commit historybitbucket_pr(action="create_pr")to create PRs
CI Context
Before confirming a branch is ready to merge, check build status (deferred — activate via tool_search first):
bamboo_builds(action="build_status")for Bamboo CIbitbucket_repo(action="get_build_statuses")for Bitbucket pipelines
Destructive Operations
If the user asks to rebase, merge, or force-push, explain that these operations are blocked for safety. Offer to help prepare the command for the user to run manually.
Common Mistakes to Avoid
- Don't assume the base branch is "main" — enterprise repos often use "develop", "master", or custom names
- Don't use
run_command("git diff origin/main")— userun_command("git diff main")instead - Don't checkout other branches to read files — use
run_command("git show <ref>:<path>")instead - Don't run
git logwith huge output — use-20or--onelineto limit - Don't forget
--followfor file history — include it ingit log --follow -- <file> - Don't reference remote refs (origin/, upstream/) — they are blocked for safety
Source: thenerdygeek/intellij-workflow-orchestrator — distributed by TomeVault.