Skip to main content

Advanced Workflows & Automation

Git Integration and Version Control

0:00
LearnStep 1/3

Git Integration and Version Control

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 status to see staged, unstaged, and untracked files.
  • Stage Changes: git add <file> or git add . to stage changes.
  • View Diffs: git diff reveals 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:

  1. Analyze: Gemini runs git diff to inspect the actual code modifications.
  2. Generate: It formulates a concise, descriptive commit message based on the diff.
  3. 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.