Integrating Git with the Gemini CLI allows for a seamless workflow where version control operations are handled directly alongside code generation and editing. Since Gemini CLI operates within your terminal environment, it can execute standard Git commands to manage your repository efficiently.
Basic Git Commands via Shell
The primary mechanism for Git interaction is the run_shell_command tool. You can instruct Gemini to perform any standard Git operation:
- Check Status:
git statusto see staged, unstaged, and untracked files. - Stage Changes:
git add <file>orgit add .to stage changes. - View Diffs:
git diffreveals what has changed, which is crucial for understanding context before committing.
Automating Commits and Messages
One of the most powerful features is automating the commit process:
- Analyze: Gemini runs
git diffto inspect the actual code modifications. - Generate: It formulates a concise, descriptive commit message based on the diff.
- Commit: It executes
git commit -m "Generated message".
Branch Management
Managing branches is essential for keeping features isolated:
- Create & Switch:
git checkout -b feature/new-api - Switch Branches:
git checkout main - List Branches:
git branch
Handling Merge Conflicts
When a merge conflict occurs, Git inserts conflict markers. Gemini can help resolve these by reading the file, analyzing conflicting sections, and using replace to keep the desired code and remove markers.