Git worktree workflow for Greptile code review on unindexed branches. Use when implementing features that need Greptile review but the target branch isn't indexed. Solves the problem of Greptile only indexing main/master branches by keeping work on main in a worktree, then branching at PR time.
Greptile only indexes main branches. This workflow lets you run Greptile reviews locally during development by working on main in a worktree, then creating a feature branch when ready to PR.
~/.config/greptile/tokencd /path/to/repo
git worktree add ../repo-worktree main
cd ../repo-worktree
Names the worktree folder repo-worktree (sibling to main repo).
Work normally in the worktree. Commit to main as you go:
git add .
git commit -m "feat: implement feature"
Always echo status before running:
echo "🔍 Greptile Review - Iteration $ITERATION_COUNT"
Then run the review:
export GREPTILE_TOKEN=$(cat ~/.config/greptile/token)
curl -s -X POST "https://api.greptile.com/v2/query" \
-H "Authorization: Bearer $GREPTILE_TOKEN" \
-H "X-Github-Token: $(gh auth token)" \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "Review the recent changes for bugs, security issues, and code quality. Be thorough."}],
"repositories": [{"remote": "github", "repository": "OWNER/REPO", "branch": "main"}],
"genius": true
}'
Replace OWNER/REPO with the actual repository path.
Echo status with issue count:
echo "🔧 Iteration $ITERATION_COUNT: Addressing $ISSUE_COUNT issues"
Fix any problems Greptile identifies. Commit fixes:
git add .
git commit -m "fix: address review feedback"
Target: 5/5 confidence score. Keep iterating until you reach it.
Repeat steps 3-4 until Greptile gives confidence score 5/5.
Echo status after each review:
echo "✅ Greptile passed with score $SCORE/5 after $ITERATION_COUNT iterations"
# OR if continuing:
echo "⚠️ Iteration $ITERATION_COUNT: Score $SCORE/5 - continuing..."
Score guidance:
Only accept 4/5 if:
If stopping at 4/5, you MUST document the specific reason in the PR description.
Stay on main. Create a branch pointing to your commits, push it, then reset main:
# Create feature branch from current HEAD
git branch feat/your-feature-name
# Push the feature branch
git push origin feat/your-feature-name
# Reset main back to remote
git reset --hard origin/main
You never checkout the feature branch—main stays clean.
gh pr create --base main --head feat/your-feature-name \
--title "feat: your feature" \
--body "Description of changes"
Remove worktree when done iterating:
cd /path/to/repo
git worktree remove ../repo-worktree
Note: You can keep the worktree if you expect to iterate further (e.g., PR at 4/5 needs more work, or waiting for human review). See "Continuing After PR" section below.
Use this when:
If worktree was cleaned up, recreate it:
cd /path/to/repo
git fetch origin
git worktree add ../repo-worktree main
cd ../repo-worktree
# Pull in the feature branch changes
git merge origin/feat/your-feature-name
If worktree still exists:
cd ../repo-worktree
git fetch origin
git merge origin/feat/your-feature-name
Then iterate:
git push origin main:feat/your-feature-name --force
git reset --hard origin/main
cd /path/to/repo
git worktree remove ../repo-worktree
Only for trivial fixes where Greptile review isn't needed:
Note: This skips local Greptile review. Only use for obvious fixes.
| Step | Command |
|---|---|
| Create worktree | git worktree add ../repo-worktree main |
| Run Greptile | curl ... (see step 3) |
| Create branch | git branch feat/name |
| Push branch | git push origin feat/name |
| Reset main | git reset --hard origin/main |
| Remove worktree | git worktree remove ../repo-worktree |