Why use Git?
Using Git provides a safety net when coding with AI. You have a complete history of every change the AI suggested and you accepted. If an AI-generated feature introduces a bug, you can instantly revert to a working version using git revert or git reset.
You can create separate branches to test different AI prompts and approaches for the same problem without messing up your main codebase. Commit messages force you to articulate the purpose of the AI's code, ensuring you understand what was added and why.
Setting up your .gitignore
Your .gitignore file tells Git which files or folders to ignore. This is essential for keeping your repository clean from auto-generated files, local configurations, and large data/model files. Create a file named .gitignore in the root of your project.
This configuration ignores common files from Cursor/VS Code, Python virtual environments, and large model or data files that shouldn't be in version control.
The "vibe coding" workflow with Git
Here is a practical, step-by-step workflow for integrating Git into your AI coding sessions.
1. Start with a clean branch
Before you start prompting the AI, always create a new branch. This isolates your AI-generated experiments. Name the branch based on the feature you're building.
2. Prompt, generate, and review
Now, start your "vibe coding" session. Use your AI agent (Cursor's chat, Claude Code, inline edits) to generate code, fix bugs, or write documentation.
After the AI generates a block of code, don't commit it immediately. First, review it carefully to ensure you understand it and that it aligns with your project's goals.
3. Make small, atomic commits
This is the most important step. Instead of committing a huge chunk of AI-generated code at once, break it down into small, logical pieces. Use Git's staging feature, git add -p (or git add --patch), to review and stage changes chunk by chunk.
When the terminal prompts you for each chunk, you can choose:
- y: Yes, stage this hunk
- n: No, do not stage this hunk
- s: Split this hunk into smaller pieces (if possible)
- e: Manually edit the hunk before staging
- q: Quit
This granular control ensures you only commit code that you've personally vetted.
4. Write intent-driven commit messages
Your commit messages should explain the why, not just the what. Since the AI wrote the code, your message adds the human context. A good format:
feat: Add user login functionality via AI
"Used Cursor to generate the initial Flask route and template. The prompt was: 'Create a Flask route at /login that handles GET and POST requests.' Reviewed the generated code for basic security and correctness."
This clarifies what feature was added, that an AI was used, the specific prompt that led to the code, and that you reviewed it.
5. Iterate and refine
Continue this cycle: prompt, generate, review, stage, commit. As you refine the feature, keep making small commits:
fix: Correct validation logic from AI suggestionrefactor: Restructure AI-generated code into servicesdocs: Add docstrings to AI functions
Once the feature is complete, push your branch and create a pull request to merge it into your main branch. This gives you one final chance to review all the AI-assisted changes together.