Books/Git Essentials/Git Cheat Sheet for AI Prompting

    Git Cheat Sheet for AI Prompting

    Git Cheat Sheet for AI Prompting

    This is your quick reference for Git commands and — more importantly — example prompts you can use with AI coding tools like Claude Code. Bookmark this page!

    Setup & Config

    CommandWhat It Does
    git --versionCheck if Git is installed
    git config --global user.name "Name"Set your name
    git config --global user.email "email"Set your email
    git config --global --listSee your configuration

    AI Prompts for Setup:

    • "Help me install Git on my [Mac/Windows/Linux]"
    • "What should I set my Git config to for a new developer setup?"
    • "Generate a .gitignore file for a [React/Python/Node] project"

    Creating Repositories

    CommandWhat It Does
    git initCreate a new repository
    git clone URLCopy an existing repository

    AI Prompts for Repos:

    • "I found this GitHub repo: [URL]. Clone it and explain the project structure to me."
    • "Help me set up a new Git repository for a [type] project"
    • "I cloned a repo but I'm not sure how to run it. Can you look at the README and help?"

    Daily Workflow

    CommandWhat It Does
    git statusSee what's changed
    git add filenameStage a specific file
    git add .Stage all changes
    git commit -m "message"Save a snapshot
    git diffSee unstaged changes
    git diff --stagedSee staged changes
    git log --onelineView commit history

    AI Prompts for Daily Work:

    • "I ran git status and see this: [paste output]. What should I do next?"
    • "Look at my git diff and review the changes I made"
    • "I've been working for a while. Help me organize my changes into logical commits."
    • "Suggest a commit message for these changes: [describe changes]"

    Branches

    CommandWhat It Does
    git branchList branches
    git checkout -b nameCreate and switch to a new branch
    git checkout nameSwitch to an existing branch
    git merge nameMerge a branch into current branch
    git branch -d nameDelete a merged branch

    AI Prompts for Branches:

    • "Create a new branch called 'feature/[name]' before we make any changes"
    • "I have a merge conflict in [file]. Here's what it looks like: [paste]. Help me resolve it."
    • "I'm done with this feature branch. Walk me through merging it into main."
    • "I messed up on this branch. How do I get back to a clean state on main?"

    Remote Repositories

    CommandWhat It Does
    git remote -vShow connected remotes
    git pushUpload commits
    git pullDownload and merge changes
    git push -u origin branchPush a new branch

    AI Prompts for Remotes:

    • "I have a local project. Help me create a GitHub repo and push my code."
    • "I'm getting a push rejection error: [paste error]. Help me fix it."
    • "Help me create a pull request for my current branch"
    • "I need to pull the latest changes but I have uncommitted work. What should I do?"

    Undoing Things

    CommandWhat It Does
    git restore --staged fileUnstage a file
    git restore fileDiscard changes to a file
    git checkout .Discard ALL uncommitted changes

    AI Prompts for Undoing:

    • "I need to undo my last commit but keep the changes"
    • "I accidentally committed a file with secrets. Help me remove it from Git history."
    • "I want to go back to how my project looked 3 commits ago. What are my options?"
    • "I ran a command and now my repo is in a weird state. Here's what git status shows: [paste]"

    Working with AI Coding Tools

    Here are prompts specifically for getting the most out of AI tools with Git:

    Before Starting Work

    • "Before we start, let's create a new branch so I can easily undo changes if needed."
    • "Check my git status. Do I have any uncommitted changes I should save first?"

    During Development

    • "Show me the git diff of what you just changed so I can review it."
    • "Commit the changes you just made with an appropriate message."
    • "I don't like the last changes. Help me revert them."

    After Changes

    • "Let's review all the changes on this branch before merging."
    • "Help me push this branch and create a pull request with a good description."
    • "Clean up: delete the feature branch since we merged it."

    When Things Go Wrong

    • "Something broke after the last change. Show me the git log so we can figure out what happened."
    • "I need to undo everything from the last 20 minutes. What are my options?"
    • "My git repo is in a weird state. Run git status and help me understand what's going on."

    The Complete Beginner Workflow

    If you remember nothing else, remember this flow:

    # Check your starting point
    git status
    
    # Create a safe branch
    git checkout -b feature/my-change
    
    # Make changes...
    
    # See what changed
    git status
    git diff
    
    # Save your work
    git add .
    git commit -m "Describe what you did"
    
    # Push to GitHub
    git push -u origin feature/my-change
    
    # When done, merge to main
    git checkout main
    git merge feature/my-change
    git push

    Keep Learning

    You now have a solid foundation in Git. Here are ways to keep building your skills:

    • Practice: Use Git in every project, even small ones
    • Ask your AI: Whenever you encounter a Git situation you don't understand, just ask
    • Explore: Try new commands in a test repository where nothing can go wrong

    Remember: Every experienced developer once Googled "how to undo a git commit." Git has a learning curve, but with AI tools by your side, you can learn faster than ever.

    Happy building!


    🌐 www.genai-mentor.ai