Skip to main content

Working with AI for Git & GitHub

Learn how to effectively work with AI assistants (like Google Antigravity) to manage Git repositories, create commits, and automate GitHub workflows.

What AI Can Do

Fully Automated Tasks

AI assistants can handle these tasks completely:

  1. Repository Setup

    • Generate SSH keys
    • Configure Git settings
    • Create repositories via API
    • Initialize local repositories
  2. Documentation & Analysis

    • Review bash history for Git commands
    • Create documentation from past work
    • Analyze repository structure
    • Generate commit message templates
  3. File Operations

    • Stage files
    • Create commits
    • Push to remote
    • Create and manage tags
  4. Configuration

    • Set up SSH configuration
    • Configure Git user settings
    • Create .gitignore files
    • Set up Git aliases
  5. Automation Scripts

    • Create repository setup scripts
    • Generate backup scripts
    • Write deployment workflows
    • Build CI/CD configurations

Tasks Requiring User Approval

These operations require your approval for security:

  1. Destructive Operations

    • Force push to repositories
    • Delete branches or tags
    • Reset commits
    • Clean untracked files
  2. Authentication

    • Pushing to remote repositories (uses your SSH key)
    • Creating repositories via API (uses your token)
    • Any operation requiring credentials
  3. System Changes

    • Installing software packages
    • Modifying system configurations
    • Changing file permissions

How to Instruct AI

Effective Prompting Strategies

Good Instructions

Be Specific and Clear:

 "Help with Git"
"Create a new repository called 'my-project' and push the contents
of /home/user/projects/my-project to GitHub"

Provide Context:

 "Fix the commit"
"Amend the last commit to change the author from 'root' to
'donnyaw <donnyaw@gmail.com>'"

Specify Locations:

 "Create SSH key"
"Generate an ED25519 SSH key at ~/.ssh/github/id_ed25519
for donnyaw@gmail.com"

State Your Goal:

 "Do git stuff"
"I want to create a release tagged v2.0.0 with the latest commits
and push to GitHub"

Prompt Templates

Repository Creation

Create a new GitHub repository named [REPO_NAME] and:
1. Initialize it locally at [PATH]
2. Add a README with [DESCRIPTION]
3. Set up .gitignore for [LANGUAGE/FRAMEWORK]
4. Make initial commit
5. Push to GitHub using SSH

Example:

Create a new GitHub repository named "backup-tools" and:
1. Initialize it locally at ~/github/backup-tools
2. Add a README describing backup automation scripts
3. Set up .gitignore for Python
4. Make initial commit
5. Push to GitHub using SSH

Commit and Tag

Please:
1. Stage all changes in [DIRECTORY]
2. Create a commit with message: [MESSAGE]
3. Create annotated tag [TAG_NAME] with message: [TAG_MESSAGE]
4. Push both commit and tag to origin

Example:

Please:
1. Stage all changes in ~/github/vps-management
2. Create a commit with message: "feat: add automated backup scripts"
3. Create annotated tag v1.2.0 with message: "Release v1.2.0 - Backup automation"
4. Push both commit and tag to origin

Documentation from History

Review my bash history and conversation logs focusing on [TOPIC].
Create comprehensive documentation covering:
- Commands used
- Configuration files
- Common workflows
- Troubleshooting steps

Save the documentation to [PATH] in MDX format for Docusaurus.

Example:

Review my bash history and conversation logs focusing on Docker deployments.
Create comprehensive documentation covering:
- Docker Compose configurations
- Container management commands
- Volume and network setup
- Troubleshooting steps

Save the documentation to /opt/docusaurus/docs/infrastructure/docker.mdx

Troubleshooting

I'm having an issue with [PROBLEM]. 
Current state: [DESCRIBE CURRENT STATE]
Expected behavior: [WHAT SHOULD HAPPEN]
Error message: [PASTE ERROR IF ANY]

Please diagnose and fix the issue.

Example:

I'm having an issue with pushing to GitHub.
Current state: Git push fails with "Permission denied (publickey)"
Expected behavior: Should push successfully using SSH
Error message: "git@github.com: Permission denied (publickey)"

Please diagnose and fix the issue.

Common AI Workflows

Workflow 1: New Repository Setup

Your Request:

Set up a new repository for my Python project:
- Name: data-processor
- Location: ~/github/data-processor
- Include: requirements.txt, .gitignore for Python, README
- Push to GitHub as private repository

AI Will:

  1. Create directory structure
  2. Generate necessary files
  3. Initialize Git repository
  4. Configure local Git settings
  5. Create GitHub repository via API
  6. Make initial commit
  7. Push to GitHub
  8. Confirm completion

Workflow 2: Release Tagging

Your Request:

Create release v2.1.0 for the vps-management repository:
1. Review recent commits since v2.0.0
2. Create annotated tag with changelog
3. Push tag to GitHub
4. Show me the release notes

AI Will:

  1. Navigate to repository
  2. List commits between tags
  3. Generate changelog
  4. Create annotated tag with detailed message
  5. Push tag to remote
  6. Display formatted release notes

Workflow 3: Commit History Analysis

Your Request:

Analyze the git history for ~/github/docker repository:
- Find all commits by me in the last month
- Identify most frequently changed files
- Create summary report

AI Will:

  1. Use git log to filter commits
  2. Analyze file change patterns
  3. Generate statistical report
  4. Create formatted summary document

Workflow 4: Fix Git Issues

Your Request:

I accidentally committed sensitive data to my last commit.
The file is config/credentials.json
Remove it from history and update .gitignore

AI Will:

  1. Remove file from last commit (amend)
  2. Add pattern to .gitignore
  3. Create new commit for .gitignore
  4. Ask for approval before force-pushing
  5. Provide instructions for team notification

Best Practices for AI Collaboration

1. Security First

Always Review Before Approving:

 Review commands that:
- Push to remote repositories
- Delete or modify history
- Change authentication
- Modify sensitive files

Never Share Sensitive Data:

 Don't paste: Private keys, passwords, tokens in plain text
Instead say: "Use the token stored in ~/.config/github/token"

2. Provide Full Context

Include Relevant Information:

Good prompt:
"I'm working on repository at ~/github/vps-management.
The remote is git@github.com:donnyaw/vps-management.git
I need to merge the feature-backup branch into main and create tag v1.5.0"

Reference Previous Work:

"Using the SSH key we set up earlier at ~/.ssh/github/id_ed25519,
configure a new repository following the same pattern we used for
the docker repository"

3. Iterative Refinement

Start Broad, Then Refine:

Step 1: "Help me set up a new repository"
Step 2: "Make it private and add a Python .gitignore"
Step 3: "Also add pre-commit hooks for code formatting"

4. Verify Results

Ask for Confirmation:

"After creating the repository, verify:
- SSH access works
- Remote is correctly configured
- .gitignore is working
- Initial commit was successful"

Advanced AI Instructions

Complex Multi-Step Workflows

Migration Project:

I need to migrate code from ~/github/03-lab/experimental to a new
production repository:

1. Create new repo: ~/github/01-production/feature-x
2. Copy only the /src and /docs directories
3. Remove any .env files and add to .gitignore
4. Create initial commit with message: "Initial production setup"
5. Create GitHub repository (private)
6. Push to remote
7. Add tag v1.0.0 with message: "Production release"
8. Document the migration process

Test each step before proceeding to the next.

Conditional Operations

Smart Commit:

Review changes in ~/github/vps-management:

If changes are only in docs/:
- Commit with message: "docs: update documentation"

If changes include scripts/:
- Run shellcheck on all .sh files first
- If passing, commit with message: "feat: update scripts"
- Create tag if version number changed

If changes include sensitive files:
- Warn me and don't commit

Repository Cleanup

Archive Old Branches:

For repository ~/github/docker:
1. List all branches that were merged into main
2. Show me the list for review
3. After my approval, delete merged branches locally and remotely
4. Create a summary of what was deleted
5. Update documentation

Common Scenarios & Solutions

Scenario 1: Quick Commit and Push

Simple Request:

Commit all changes in ~/github/vps-management with message
"update backup scripts" and push to GitHub

What AI Does:

cd ~/github/vps-management
git add .
git commit -m "update backup scripts"
git push

Scenario 2: Emergency Rollback

Urgent Request:

URGENT: The last commit to production broke things.
Repository: ~/github/docker
Revert the last commit and push immediately.

What AI Does:

cd ~/github/docker
git revert HEAD
# Reviews the changes
# Asks for approval
git push origin main

Scenario 3: Documentation Generation

Documentation Request:

Create comprehensive Git/GitHub documentation based on:
- Our conversation history about Git
- My bash history commands
- SSH and API token setup we did

Organize it in MDX format at /opt/docusaurus/docs/code/git-github/
Include real examples and current configuration.

What AI Does:

  1. Searches conversation logs for Git discussions
  2. Extracts bash history commands
  3. Analyzes current configuration files
  4. Creates structured MDX documentation
  5. Includes tested code examples
  6. Adds cross-references
  7. Verifies file structure

Scenario 4: Bulk Operations

Batch Request:

For all repositories in ~/github/01-production/:
1. Check if they have uncommitted changes
2. Pull latest from origin
3. Check if they're behind remote
4. Create a status report

Don't make any changes, just report.

What AI Does:

for repo in ~/github/01-production/*/; do
cd "$repo"
# Check status
# Compare with remote
# Generate report
done

AI Limitations & Workarounds

What AI Cannot Do (and Alternatives)

Cannot: Access Web UI Directly

Instead, ask for:

"Give me the curl commands to create a repository via API"
"Provide step-by-step instructions for adding SSH key on GitHub web interface"

Cannot: Store Permanent Memory Between Sessions

Instead, use:

"Document this workflow in ~/documents/git-workflows/release-process.md
so we can reference it next time"

Cannot: Access External Services Directly

Instead, request:

"Generate a GitHub Actions workflow file that will run on push"
"Create a webhook payload example for testing"

Working Around Limitations

Use Documentation:

"Create a script that I can run manually that will:
1. Check repository status
2. Create commit
3. Push to GitHub

Save it as ~/scripts/quick-commit.sh"

Create Checklists:

"Generate a checklist for release process that I can follow,
including all git commands needed"

Tips for Maximum Efficiency

1. Use Specific Terminology

 "Create annotated tag" (AI knows this is git tag -a)
"Amend last commit" (AI knows this is git commit --amend)
"Interactive rebase" (AI knows this is git rebase -i)

2. Reference Past Work

"Use the same repository structure we set up for the docker project"
"Follow the commit message format from the vps-management repository"
"Apply the .gitignore pattern we used last time"

3. Request Verification

"After each step, verify it worked correctly before proceeding"
"Run git status after staging to confirm correct files"
"Test SSH connection before attempting to push"

4. Ask for Explanations

"Explain what each git command does before running it"
"Show me what will be committed before actual commit"
"List files that will be affected by this operation"

Example Conversation Flow

Complete Workflow Example

You:

I want to start a new project for monitoring VPS resources.
Help me set it up properly with Git and GitHub.

AI:

I'll help you set up a new project. Let me clarify a few things:
1. What should we name the repository? (e.g., vps-resource-monitor)
2. Where should it be located? (e.g., ~/github/01-production/)
3. What programming language/framework?
4. Should it be public or private on GitHub?

You:

- Name: vps-monitor
- Location: ~/github/01-production/vps-monitor
- Language: Python
- Make it private

AI:

Perfect! I'll:
1. Create directory structure
2. Initialize Git repository
3. Generate Python .gitignore
4. Create README.md
5. Set up requirements.txt
6. Make initial commit
7. Create private GitHub repository
8. Push to remote

Proceeding now...

[AI executes all steps]

AI:

 Repository created successfully!

Summary:
- Local: ~/github/01-production/vps-monitor
- Remote: git@github.com:donnyaw/vps-monitor.git (private)
- Initial commit: "Initial commit - VPS monitoring project"
- Files created: README.md, .gitignore, requirements.txt

Next steps:
1. Add your monitoring scripts
2. Update requirements.txt with dependencies
3. When ready, I can help you create the first release tag

Would you like me to create a project structure for the monitoring scripts?

Quick Reference Commands for AI

Most Useful Requests

# Quick commit and push
"commit all changes with message 'update docs' and push"

# Create release tag
"create tag v1.0.0 with message 'initial release' and push it"

# Fix last commit
"amend last commit to change message to '[new message]'"

# Repository status
"show me the status of all repositories in ~/github/01-production"

# Create new repo
"create repository [name] at [path] and push to GitHub"

# Documentation
"document our Git workflow based on bash history"

# Cleanup
"show me all merged branches that can be deleted"

# Backup
"create a backup script for all Git repositories"

Security Checklist

Before asking AI to perform operations, ensure:

  • SSH keys are properly configured
  • Sensitive files are in .gitignore
  • API tokens are stored securely (not in code)
  • You review destructive operations before approval
  • Force-push operations are necessary and safe
  • Repository visibility (public/private) is correct
  • Commit messages don't contain sensitive info
  • Remote URLs use SSH (not HTTPS with embedded tokens)