Learning HubACFS Academy
Progress
0%
0 of 2020 remaining
  • 1
    Welcome & Overview5 min
  • 2
    Linux Navigation8 min
  • 3
    SSH & Persistence6 min
  • 4
    tmux Basics7 min
  • 5
    Git Essentials10 min
    NOW
  • 6
    GitHub CLI8 min
  • 7
    Agent Commands10 min
  • 8
    NTM Command Center8 min
  • 9
    NTM Prompt Palette6 min
  • 10
    The Flywheel Loop10 min
  • 11
    Keeping Updated4 min
  • 12
    UBS: Code Quality Guardrails8 min
  • 13
    Agent Mail Coordination10 min
  • 14
    CASS: Learning from History8 min
  • 15
    The Memory System8 min
  • 16
    Beads: Issue Tracking8 min
  • 17
    Safety Tools: SLB & CAAM6 min
  • 18
    The Art of Agent Direction12 min
  • 19
    Case Study: cass-memory15 min
  • 20
    Case Study: SLB12 min
Back to Home
Back
5/20
Lesson 5
10 min

Git Essentials

Version control and recognizing dangerous operations

New to ACFS?

Complete the setup wizard first to get the most from these lessons.

Go to Choose Your OS
Goal

Master git basics and recognize dangerous operations before they happen.

What Is Git?

Git is a version control system that tracks changes to your code over time. Think of it like a detailed history of every change you've ever made, with the ability to go back to any point.

Full History

Every change is recorded and reversible

Branching

Work on features without affecting main code

Collaboration

Multiple people can work on the same project

Safety Net

Recover from mistakes (if you know how)

Core Concepts

Repository

A project folder tracked by git (contains a .git directory)

Example: git init creates a new repository

Commit

A snapshot of your code at a point in time

Example: Like saving a checkpoint in a game

Staging Area

Where you prepare changes before committing

Example: git add puts files in staging

Branch

An independent line of development

Example: main, feature/login, bugfix/auth

Remote

A copy of your repository on a server (like GitHub)

Example: origin is the default remote name

Essential Commands

See what's changed (run this often!)
Stage a file for commit
Stage all changes
Create a commit with a message
Upload commits to remote
Download and merge remote changes
View commit history
See uncommitted changes

Understanding .gitignore

The .gitignore file tells git which files to ignore. This is critical for security because you never want to commit:

.envContains API keys and secretsSecurity Risk
node_modules/Dependencies (huge, regeneratable)
.venv/Python virtual environments
*.logLog files with potentially sensitive data
credentials.jsonService account keysSecurity Risk
.claude/Claude Code session data
Warning
Never commit secrets! If you accidentally commit an API key, consider it compromised. Rotate it immediately.

Working with Branches

List all local branches
Create a new branch
Switch to a branch
Create and switch in one command
Merge branch into current branch
Delete a merged branch
Pro Tip
Always create a new branch for features or experiments. Keep main stable.

Dangerous Operations

AI agents may propose these commands. Know what they do before approving them:

git reset --hard

Effect: Destroys all uncommitted changes permanently

Alternative: git stash (saves changes for later)

git clean -fd

Effect: Deletes all untracked files permanently

Alternative: Review with git clean -n first (dry run)

git push --force

Effect: Overwrites remote history, can delete teammates' work

Alternative: git push --force-with-lease (safer)

git checkout .

Effect: Discards all uncommitted changes to tracked files

Alternative: git stash or commit first

git rebase main

Effect: Rewrites commit history (can cause conflicts)

Alternative: Only rebase unpushed commits

rm -rf .git

Effect: Destroys entire repository history forever

Alternative: There is no alternative. Never do this.

Warning
Before approving any git command from an agent:
1. Run git status to see current state
2. Run git stash to save uncommitted work
3. Only then proceed with destructive commands

Recovery Tools

When things go wrong, these commands can help:

Temporarily save uncommitted changes
Restore stashed changes
View history of HEAD (find lost commits)
Undo last commit, keep changes staged
Discard changes to a specific file
Create new commit that undoes a previous one
bash
# Lost a commit after reset --hard? Find it!
$ git reflog
# Look for your commit hash, then:
$ git checkout <hash>
# Or create a branch at that commit:
$ git branch recovery <hash>

Best Practices with Agents

Commit early and often

Small commits are easier to revert. Agents work better with clear history.

Always run git status before destructive commands

Know what you're about to lose before you lose it.

Use git stash as your safety net

Stash uncommitted work before letting agents run risky operations.

Review agent-proposed git commands

Agents may suggest --force or reset --hard. Always understand before approving.

Push your work frequently

Remote backups protect against local disasters.

Try It Now

bash
1# Check your repository status
2$ git status
3
4# View recent commits
5$ git log --oneline -5
6
7# See what's in your .gitignore
8$ cat .gitignore
9
10# Practice stashing (safe to try!)
11$ echo "test" > temp.txt
12$ git stash
13$ git stash pop
14$ rm temp.txt

Ready to level up?

Mark complete to track your learning progress.

Previous
tmux Basics
Next
GitHub CLI