How it works (mapped to source)
- Parse args via Commander (main action wrapper).
- Repo check: if not a git repo →
git init. - Remote: if
--remoteprovided → attemptgit remote add origin <url>(ignore if exists). - Detect first commit (rev-parse HEAD).
- Branch logic:
- If
--no-branchOR no commits → force/create main (git checkout -B main). - Else interactive: current branch vs create new branch.
- Open source mode (
--osc): prompts for issue number, creates branchtype/#<issue_number>-shorttitle.- If
--genieis used, short title is generated by Gemini. - Otherwise, uses the message from
gg "message".
- If
- AI-generated branch name:
<type>-<kebab-case-desc>(max 40 chars) if not using--osc.
- Staging: if no staged diff → auto stage all (./*) → re-check; error if still empty.
- AI commit generation (if
--genie& key): send staged diff to Gemini modelgemini-2.0-flashwith strict prompt; capture plain message. - Commit:
git commit "<message>". - Push flow:
- If
--push-to-mainand not on main → merge helper (see below). - Else prompt to push; if yes → push with retry (2 retries).
- If pushed and branch != main → optional prompt to merge to main.
- Optional merge to main: checkout main → pull → merge feature → push → optional delete local + remote branch.
Common workflows
Feature with AI + push:
gg "add oauth flow" --type feat --scope auth --genie
Direct quick fix on main:
gg "fix typo in README" --no-branch --genie
Initialize new repo + remote:
gg "initial commit" --no-branch --remote https://github.com/you/repo.git --genie
Auto merge after finishing work:
gg "implement payment flow" --push-to-main
Open source contribution:
gg "update docs for API v2" --type docs --osc # Prompts for issue number, creates branch: docs/#789-update-docs-for-api-v2
Branch & merge behavior
- AI-generated branch names: conventional type prefix + kebab-case description (max 40 chars).
--oscbranch names:type/#<issue_number>-shorttitle(short title from Gemini or message).--push-to-maintriggers: checkout main → pull (non-fatal if remote missing) → merge → push main → optional feature cleanup.- Branch cleanup: interactive confirm; deletes local + tries remote (ignored if absent).