data-science · English · 8 min
🇻🇳 Đọc tiếng ViệtGit and GitHub: Essential Tools in the Vibe Coding Era
May 16, 2026
AI tools like Claude Code and GitHub Copilot write code better than ever. But that's exactly why Git matters more now — so you can see what AI actually changed, and undo it when you need to.
Vibe coding is changing how we work. With Claude Code, GitHub Copilot, or Cursor, you can generate hundreds of lines of code from a single prompt. The quality is good enough to run. Good enough to ship.
But a new problem has emerged: do you actually know what the AI just did?
When AI writes code on your behalf, reviewing it becomes far more complex. You no longer remember which lines were added when, why, or what changed since the last version. A 30-minute vibe coding session can produce 500 lines of changes spread across 10 files — without Git, you're essentially flying blind.
This is why Git and GitHub matter more than ever in the AI-assisted coding era. Not just to track what you write, but to track what AI has done to your codebase.
How Git Works
Git organizes your work across three areas:
| Area | Role | Command |
|---|---|---|
| Working Directory | Where you (or AI) edit files | (you're here) |
| Staging Area | Choose which changes to save | git add |
| Repository | Saved history, never lost | git commit |
The basic workflow: edit files → git add → git commit. That's it.
Practical commands you'll use every day
Getting started
# Clone a repo to your machine
git clone https://github.com/user/repo.git
# Or initialize a new repo in the current folder
git initChecking what changed
# See which files have changed
git status
# See exactly what changed, line by line
git diff
# See the commit history
git log --onelinegit status and git diff are the two commands you should run most often when working with AI — always check what changed before you commit.
Saving changes
# Stage all changes
git add .
# Or stage a specific file (more deliberate)
git add src/main.py
# Commit with a descriptive message
git commit -m "feat: add user authentication"Vibe coding tip: Don't commit an entire AI session in one shot. Commit in small, focused chunks so each change is easy to review — and easy to roll back if something breaks.
Working with branches
Branches let you experiment without touching the main codebase. This is especially important with AI: always let AI work on a separate branch.
# Create a new branch and switch to it
git checkout -b feature/feature-name
# See which branch you're on
git branch
# Switch back to main
git checkout main
# Merge your branch into main (after reviewing it)
git merge feature/feature-name
# Delete the branch after merging
git branch -d feature/feature-nameSyncing with GitHub
# Push code to GitHub
git push origin main
# Pull the latest changes
git pull origin main
# Fetch changes without merging (preview first)
git fetch originWhen things go wrong — how to undo
This is the most important section for AI-assisted development: knowing how to undo.
Undo uncommitted changes
# Discard changes in a specific file (reverts to last commit)
git checkout -- filename.py
# Discard ALL uncommitted changes (CAREFUL: cannot be undone)
git checkout -- .Undo a recent commit
# Undo the commit but KEEP the changes (safest option)
git reset --soft HEAD~1
# Undo the commit and unstage the changes
git reset HEAD~1
# Undo the commit and DELETE the changes (dangerous — code is gone)
git reset --hard HEAD~1Rule of thumb: when unsure, use --soft. Your code stays intact; you just remove the commit wrapper around it.
Browse history to find a safe point
# View condensed commit history
git log --oneline
# Preview a specific commit (read-only, nothing changes)
git checkout abc1234
# Create a new branch from an older commit
git checkout -b recovery-branch abc1234When AI generates a mess of changes you want to throw away entirely, git log --oneline + git reset is the combination that saves you.
GitHub — the Pull Request workflow
GitHub is where you store code online and collaborate with others. Pull Requests (PRs) are how you review code before merging — particularly useful when reviewing AI-generated changes.
The basic flow
# 1. Create a new branch
git checkout -b feature/add-login
# 2. Write code (or let AI write it)
# 3. Commit
git add .
git commit -m "feat: add login form"
# 4. Push the branch to GitHub
git push origin feature/add-login
# 5. Open GitHub, create a Pull Request
# 6. Review the code, merge when it looks goodSee exactly what changed between branches
# Commits on the feature branch that main doesn't have yet
git log main..feature/add-login --oneline
# Full line-by-line diff between branches
git diff main..feature/add-loginThis is your AI review workflow: before merging, run git diff main..feature-branch to see every single line the AI changed — nothing hidden, nothing skipped.
Git Flow — a branching workflow for real projects
Git Flow is a branching model designed for projects with defined release cycles. Instead of working directly on main, Git Flow assigns specific roles to different types of branches.
Branch structure in Git Flow
main ← code running in production
develop ← integration point for all new features
feature/* ← individual feature development
release/* ← preparing a new version for release
hotfix/* ← urgent fixes applied directly from main
Lifecycle of a new feature
Step 1: Create a feature branch from develop
git checkout develop
git pull origin develop # make sure develop is up to date
git checkout -b feature/user-authenticationStep 2: Develop the feature
# Write code (or let AI work on this branch)
git add .
git commit -m "feat: add login form"
git commit -m "feat: add JWT token handling"Step 3: Sync new changes from develop into your branch
In practice, while you're building a feature, teammates (or AI on other branches) keep merging code into develop. You need to pull those changes into your branch regularly to avoid large conflicts when you merge later.
Two options:
Option 1 — Merge develop into your feature branch (simpler, safer):
git checkout develop
git pull origin develop # get the latest changes on develop
git checkout feature/user-authentication
git merge develop # bring develop's changes into your branch
# resolve any conflicts, then commitOption 2 — Rebase your feature branch onto develop (cleaner commit history):
git checkout feature/user-authentication
git rebase develop # replay your commits on top of develop
# resolve conflicts one commit at a time if needed
# git rebase --continue # after resolving each stepWhich to choose? Merge is simpler and lower risk — it works well for most situations. Rebase produces a linear, cleaner history but is more complex when conflicts arise. If you're still getting comfortable with Git, start with merge.
Step 4: Merge the feature into develop when complete
git checkout develop
git merge feature/user-authentication
git push origin develop
git branch -d feature/user-authenticationPreparing a release
# 1. Create a release branch from develop
git checkout develop
git checkout -b release/1.2.0
# 2. Bug fixes only — no new features
git commit -m "fix: correct date format in reports"
# 3. Merge into main (to deploy) and develop (to stay in sync)
git checkout main
git merge release/1.2.0
git tag -a v1.2.0 -m "Release version 1.2.0"
git checkout develop
git merge release/1.2.0
git branch -d release/1.2.0Handling a production emergency
# 1. Create a hotfix branch from main
git checkout main
git checkout -b hotfix/fix-payment-crash
# 2. Fix the bug
git commit -m "fix: resolve payment crash on checkout"
# 3. Merge into both main and develop
git checkout main
git merge hotfix/fix-payment-crash
git tag -a v1.2.1 -m "Hotfix: payment crash"
git checkout develop
git merge hotfix/fix-payment-crash
git branch -d hotfix/fix-payment-crashGit Flow with AI coding
Git Flow works especially well with AI because it creates clear boundaries:
- Let AI code on
feature/*branches only — never let AI work directly ondevelopormain - Review carefully before merging into
develop— this is your most important checkpoint - One feature branch = one feature — makes it easy to run
git diff develop..feature/nameand see exactly what AI changed
Note: Git Flow suits projects with defined release cycles (apps, libraries). For blogs, small side projects, or notebooks, a simpler workflow — just
main+ feature branches — is usually enough.
Habits worth building now
Commit often, commit small. Each commit should represent one meaningful unit of change. With AI coding, commit after each small feature rather than letting a thousand lines pile up in a single commit.
Write commit messages that mean something. Instead of "fix", write "fix: resolve login error when email contains uppercase letters". You'll thank yourself weeks later when you need to trace what happened.
Never commit your .env file. API keys, passwords, and credentials must never go into Git. Create a .gitignore file and add .env to it.
# Create .gitignore
echo ".env" >> .gitignore
echo "__pycache__/" >> .gitignore
echo "node_modules/" >> .gitignore
git add .gitignore
git commit -m "chore: add gitignore"Always create a branch before letting AI code. If the AI produces something unusable, you can delete the branch and start fresh — the code on main stays safe.
Common Git mistakes when using AI tools
Committing an entire AI session in one shot. After 30 minutes of vibe coding, you run git add . && git commit -m "update". Result: 500 lines of changes, one commit, impossible to review. Commit after each small feature instead.
Skipping git diff before committing. AI can delete code you wrote, add unnecessary dependencies, or modify unrelated files. Running git diff before each commit takes 30 seconds and catches most of these issues.
Letting AI code directly on main. If the AI produces something unusable, there's no safe way to roll back. Always create a branch first (git checkout -b feature/name), let AI work there, review it, then merge.
Using git reset --hard when unsure. --hard permanently deletes changes in your working directory — there's no recovery. In most situations, --soft is the safer choice: your code stays intact, only the commit is removed.
Committing .env because you forgot .gitignore. This happens more than you'd think, especially when AI creates new files. If you've already committed it, run git rm --cached .env to untrack the file, then add it to .gitignore.
Key takeaways
- Git now tracks what AI does, not just what you write — this is why Git matters more in the vibe coding era
- Run
git statusandgit diffbefore every commit — this single habit catches most problems before they enter the repo - Commit small, commit often — each commit should be a meaningful unit, easy to review and easy to roll back
- Always use a branch when letting AI code — if the AI makes a mess, delete the branch and start over;
mainstays safe - Know how to undo:
git reset --softis your safest bet — keeps your code, removes the commit, nothing is lost