AI Coding Agents

Learn Git Now: A Hands-On Guide for Working With AI Agents

Before an AI agent touches your code, make a save you know you can get back to. That's NetworkChuck's lesson in You Need to Learn Git Right Now. His practice project is small enough to understand completely: one web page and one short zombie story. You save it, break it, recover it, then let an agent propose a change without giving it the merge button.

Git is the version-control tool. It tracks snapshots on your computer and works without an account. GitHub is a host for Git repositories, with collaboration features such as issues and pull requests. Do the first four exercises locally before connecting anything to GitHub.

Watch the NetworkChuck Tutorial

Open NetworkChuck's companion guide for the original commands in order. The exercises below use a few narrower defaults for beginners. Run each command in order, stopping if it fails. Replace uppercase placeholders with your own values.

1. Make a Save Point Before the Agent Starts

Install Git for your operating system and check it with git --version. Open a new, empty practice folder outside your existing repositories. In a plain-text editor, create index.html with <h1>The night shift</h1>, zombiestory.md with a sentence such as Someone knocked after closing time., and .gitignore with .env on its own line. Save the files without an extra .txt extension.

Set your commit identity for this repository rather than changing your settings everywhere. Commit identity is separate from GitHub sign-in. Use your GitHub-provided no-reply address if you don't want your personal email in hosted commit history. The video uses git config --global init.defaultBranch main; git init -b main names just this repo's first branch.

Initialize and stage the demo files

Ready to copy

Once the staged diff contains only your three intended files, run git commit -m "Add the first website and story", then git log --oneline. This is your first save. git add . also works, but can stage everything under the current directory, including unrelated edits and unignored new files. Named paths are easier to inspect.

2. Read the Diff You're Actually About to Commit

Edit one line in zombiestory.md and save. git status -sb summarizes the state; git diff -- zombiestory.md shows tracked working-copy changes not staged yet. After git add -- zombiestory.md, use git diff --staged to see what the next commit will record. Plain git diff can be empty at that point even though a change is ready to commit. A new untracked file won't appear in the ordinary diff; check status too.

Stage only what belongs in the checkpoint, commit with a message such as git commit -m "Continue the story", and confirm the new commit appears in git log --oneline. Repeat that habit before and after a coding agent works, so unrelated edits don't get buried in a big commit.

3. Undo a File Edit or Look at an Old Commit

What you meanCommandWhat it does
Unstage this filegit restore --staged -- zombiestory.mdRemoves the file's staged change from the next commit and keeps the working copy.
Discard this file's unstaged editsgit restore -- zombiestory.mdOverwrites the working copy from the staging area. Only run after checking the diff and deciding the edits can go.
Read a past file without switchinggit show COMMIT_HASH:zombiestory.mdPrints the saved file without changing the working copy.
Inspect the whole old projectgit switch --detach COMMIT_HASHChecks out a historical snapshot without moving a branch. Return with git switch main.

Try the discard command only on a deliberately bad edit in the practice repo. Restore's default source is the index, not necessarily the last commit. The video uses git checkout COMMIT_HASH for time travel; git switch --detach makes the intent explicit. Use it with a clean working tree and don't commit there unless you create a branch to keep the work. Neither command is a rewind button for a change you already shipped to a shared branch.

4. Make an Alternate Timeline and Bring It Back

From clean main, run git switch -c zombieattack. It combines the video's git branch zombieattack and git switch zombieattack. Add a line to your story. Review, stage and commit it on the branch. Then switch back to main: the branch's committed change is not there yet.

Compare and merge the local branch

Ready to copy

Run the last line only after reviewing the comparison. Once merged and checked, git branch -d zombieattack removes the local branch name, not its merged changes. A branch is a pointer to commits; two branches in one checkout do not give two agents independent folders. For concurrent work, give each a separate clone or Git worktree.

5. Put the Demo on GitHub Without Sending Secrets

For the optional hosted half, install the GitHub CLI, run gh --version, and sign in to your own GitHub account with gh auth login. Before creating the remote, run git status --short --ignored and git ls-files -- .env. The latter should return nothing. Inspect the commits you intend to upload, not just today's file tree.

Git ignore rules keep untracked files out of normal staging. They do not untrack a file or erase old commits. If a file was already tracked, git rm --cached -- .env stages its removal from the index but leaves the local file. If a real credential was exposed, revoke or rotate it first. A private repo is not a vault.

Create an empty remote only in the account you intend to use. If this local repo already has an origin, stop and inspect it rather than adding or replacing it blindly. Substitute the actual owner and repository name below, verify the printed remote, and only then push the reviewed history.

Create a private remote and verify its URL

Ready to copy

Push with git push -u origin main. The -u sets the upstream so later pushes and pulls can use it. If HTTPS Git commands still ask for credentials after login, gh auth setup-git configures the CLI as a credential helper. From a different parent folder, try git clone YOUR_REPO_URL git-practice-second. In the clone, git fetch origin updates your view of the remote without merging into your checked-out branch; git branch -a displays local and remote-tracking branches. On a clean local main, git pull --ff-only updates it or stops if it has diverged.

6. Give the Agent One Issue. Keep the Merge Button.

In your private demo repo, create an issue with gh issue create --title "Add a line" --body "Add exactly one line to zombiestory.md; change no other files." The issue is the work request, not permission to merge. Give your agent the issue number and a separate clone or worktree with only the access it needs.

Copyable agent handoff

Ready to copy

Replace PR_NUMBER below. Review the changes and required checks first, then use gh pr checkout PR_NUMBER in a clean review checkout if you need to run tests or inspect the site. Treat code from unfamiliar contributors as untrusted; don't run it with access to secrets. A review comment or passing test is evidence to consider, not sign-off by itself.

Inspect the pull request before checkout

Ready to copy

After a human approves and checks pass, gh pr merge PR_NUMBER --merge requests a merge commit if the repository allows that method. Use required reviews and checks when your GitHub plan and repository settings support them. In the two-file exercise there may be no CI, so open the site and verify the changed behavior yourself.

7. Cause a Conflict in the Lab, Then Resolve It

In your throwaway project, commit different replacements for the same line in index.html on main and on a branch created before that edit. Two commits touching the same file don't always conflict; conflicting edits to the same lines make this example easier to reproduce.

The video resolves a simple conflict in GitHub's editor. Locally, if the PR branch is yours and clean, fetch and merge origin/main into that branch. When Git stops, use git status to find unmerged files. Read both versions, edit the final content, and remove the <<<<<<<, =======, and >>>>>>> markers. Stage the resolved file and run git merge --continue; verify the result, push the branch and re-review the PR. Use git merge --abort if you need to back out of the unfinished merge. Don't choose a side by label alone, and don't start a merge with unrelated local changes.

8. Undo Something That Already Merged

In the final exercise, NetworkChuck uses GitHub's Revert button on the merged pull request. GitHub creates another PR to propose the reversal. Review and test it before merging. If you just need to undo one ordinary commit, git revert COMMIT_HASH creates a new inverse commit; merge commits need extra care because you must identify the right parent. Neither approach erases the original history. A source-code revert also doesn't automatically reverse a database migration or redeploy a previous version.

The workflow to keep: commit a known-good state, assign one issue, review the branch diff, verify the behavior, then decide whether to merge. The agent can do the typing. You still decide what ships.

Video Chapters

TimeChapter
00:00Why Git is not GitHub
01:15CodeRabbit review demo (sponsor)
03:01Install Git and make a tiny repo
05:01Status, staging and your first commit
07:28Read a diff
09:03Restore a file
09:53Inspect an old commit
11:07Create a branch
14:05Merge into main
15:13Create a GitHub repo
17:19Keep local secrets out of Git
18:17Add origin and push
19:34Clone and pull
22:06Give an issue to a coding agent
27:05Review and merge a pull request
31:01Create a merge conflict
32:37Resolve the conflict
34:36Revert a merged PR
35:34Closing prayer

Resources and Disclosure

This guide follows NetworkChuck's video and his complete companion repository, with safeguards from the linked Git and GitHub docs. Episode sponsor: CodeRabbit via NetworkChuck's link. CodeRabbit lists a 14-day trial with no credit card. It's optional; use review automation to help spot issues, not as a replacement for your own review. Source check: 18 November 2026.

Common questions

Is Git the same as GitHub?
No. Git is the version-control tool that tracks commits on your computer. GitHub hosts Git repositories and adds collaboration tools such as issues and pull requests. You can learn the local commands without a GitHub account.
What is the difference between restore and revert?
Restore can replace uncommitted file content with a Git snapshot. Revert records a new commit that undoes a previous commit without rewriting shared history. Inspect the diff before choosing either.
Does .gitignore remove a leaked API key?
No. It prevents an untracked file from being added normally; it does not untrack existing files or erase previous commits. Revoke or rotate an exposed key first.
Share
X LinkedIn Reddit
Build Yours

Want a system
like this one?

Book a free 30-minute call. We map your situation, identify the highest-impact automation, and figure out if we are a fit.

Book Free 30-min Call