NerdSystem Course
Getting Started0/5
  • 1.Welcome to Nerd System
  • 2.Setting Up Your Tools
  • 3.Your First Next.js Project
  • 4.Git and GitHub Essentials
  • 5.The AI-First Development Workflow
Claude Code Essentials0/3
  • 1.Introduction to Claude Code
  • 2.Prompting Strategies and Plan Mode
  • 3.Context, CLAUDE.md, and MCP
Advanced Claude Code0/4
  • 1.Agents, Sub-Agents, and Extended Thinking
  • 2.Hooks, Skills, and Slash Commands
  • 3.Iterative Building and Working with Existing Code
  • 4.Code Auditing with Claude Code
Infrastructure0/6
  • 1.Domains and DNS
  • 2.Servers and Hosting Explained
  • 3.Databases for App Developers
  • 4.Environment Variables and Configuration
  • 5.Deployment Pipelines with GitHub Actions
  • 6.Going Live — Domain to Deployment
Building with AI0/6
  • 1.Project Planning with AI
  • 2.Database Schema and Drizzle Setup
  • 3.API Routes and Server Actions
  • 4.Building the UI with Components
  • 5.Authentication and User Data
  • 6.Testing and Deploying Your App
Security0/5
  • 1.Security Fundamentals
  • 2.Authentication Deep Dive with Clerk
  • 3.Authorization — Protecting What Matters
  • 4.Secrets Management in Practice
  • 5.HTTPS, Headers, and Production Hardening
Business Operations0/5
  • 1.Setting Up Billing with Stripe
  • 2.Analytics and Monitoring
  • 3.Legal Basics — Privacy, Terms, Compliance
  • 4.Custom Domains, Email, and Professional Setup
  • 5.Launch Day — Zero to Real Users
Ship Kit0/6
  • 1.100+ Elite Prompts for AI Coding Assistants
  • 2.AI Coding Loop Escape Guide
  • 3.Project Management Workflows for AI Builds
  • 4.Common Pitfalls Encyclopedia
  • 5."AI Can't Do This" Cheat Sheet
  • 6.Tech Stack Decision Matrix
HomePricingHelp & Support
Terms·Privacy·Refund
NerdSystem Course
Getting Started0/5
  • 1.Welcome to Nerd System
  • 2.Setting Up Your Tools
  • 3.Your First Next.js Project
  • 4.Git and GitHub Essentials
  • 5.The AI-First Development Workflow
Claude Code Essentials0/3
  • 1.Introduction to Claude Code
  • 2.Prompting Strategies and Plan Mode
  • 3.Context, CLAUDE.md, and MCP
Advanced Claude Code0/4
  • 1.Agents, Sub-Agents, and Extended Thinking
  • 2.Hooks, Skills, and Slash Commands
  • 3.Iterative Building and Working with Existing Code
  • 4.Code Auditing with Claude Code
Infrastructure0/6
  • 1.Domains and DNS
  • 2.Servers and Hosting Explained
  • 3.Databases for App Developers
  • 4.Environment Variables and Configuration
  • 5.Deployment Pipelines with GitHub Actions
  • 6.Going Live — Domain to Deployment
Building with AI0/6
  • 1.Project Planning with AI
  • 2.Database Schema and Drizzle Setup
  • 3.API Routes and Server Actions
  • 4.Building the UI with Components
  • 5.Authentication and User Data
  • 6.Testing and Deploying Your App
Security0/5
  • 1.Security Fundamentals
  • 2.Authentication Deep Dive with Clerk
  • 3.Authorization — Protecting What Matters
  • 4.Secrets Management in Practice
  • 5.HTTPS, Headers, and Production Hardening
Business Operations0/5
  • 1.Setting Up Billing with Stripe
  • 2.Analytics and Monitoring
  • 3.Legal Basics — Privacy, Terms, Compliance
  • 4.Custom Domains, Email, and Professional Setup
  • 5.Launch Day — Zero to Real Users
Ship Kit0/6
  • 1.100+ Elite Prompts for AI Coding Assistants
  • 2.AI Coding Loop Escape Guide
  • 3.Project Management Workflows for AI Builds
  • 4.Common Pitfalls Encyclopedia
  • 5."AI Can't Do This" Cheat Sheet
  • 6.Tech Stack Decision Matrix
HomePricingHelp & Support
Terms·Privacy·Refund
Getting Started>Lesson 4 of 5

12 min read

Git and GitHub Essentials

Learn the 20% of Git that covers 95% of what you'll need — then push your project to GitHub.

Why Git Matters

Your project is sitting on your machine right now. If your hard drive dies, it's gone. If you make a bad change, you can't undo it. If you want to collaborate, there's no way to share it.

Git solves all of this. It tracks every change you make, lets you rewind to any point in time, and syncs your code to the cloud via GitHub.

The good news: you only need a handful of commands to be productive. Let's cover them.

The Core Commands

There are really only seven Git commands you'll use constantly. Everything else is edge cases.

0 of 7 complete
git init — Start tracking a project

This creates a hidden .git/ folder in your project that stores the entire history. You only run this once per project.

cd nerdsystem-app
git init
git add — Stage your changes

Before you can save a snapshot, you tell Git which changes to include. This is called "staging."

# Stage a specific file
git add src/app/page.tsx
 
# Stage everything that changed
git add .
git commit — Save a snapshot

A commit is a saved checkpoint. Each one gets a unique ID and your message describing what changed.

git commit -m "update home page with custom heading"
git push — Upload to GitHub

Push sends your commits from your machine to a remote repository on GitHub.

git push origin main
git pull — Download changes

Pull grabs the latest commits from GitHub — useful when you work from multiple machines or with other people.

git pull origin main
git branch — Create a parallel version

Branches let you work on a feature without touching the main codebase. If things go wrong, main is untouched.

git branch new-feature
git checkout — Switch between branches

Move between branches to work on different things.

git checkout new-feature
 
# Shortcut: create AND switch in one command
git checkout -b another-feature

You can ask Claude Code to handle git operations: "Create a new branch called add-about-page, make this change, commit it, and push to GitHub." It's especially useful for complex git operations like rebasing or resolving merge conflicts.

The Workflow in Action

Here's what the full cycle looks like when you make a change:

$ cd nerdsystem-app
$ git init
Initialized empty Git repository in /home/you/nerdsystem-app/.git/

$ git add .

$ git commit -m "initial commit: scaffold Next.js project"
[main (root-commit) a1b2c3d] initial commit: scaffold Next.js project
18 files changed, 3847 insertions(+)
create mode 100644 .gitignore
create mode 100644 package.json
create mode 100644 src/app/layout.tsx
create mode 100644 src/app/page.tsx
...

That's it — your project is now tracked. Every future change gets layered on top of this snapshot.

Push to GitHub

Now let's back it up to the cloud. You'll need the GitHub repo created first.

0 of 4 complete
Create a repo on GitHub

Go to github.com/new. Name it nerdsystem-app. Leave it empty — don't add a README or .gitignore (we already have those).

Authenticate with GitHub

Before you can push, GitHub needs to know who you are. The easiest method is the GitHub CLI:

brew install gh

Then log in:

$ gh auth login

? What account do you want to log into? GitHub.com
? What is your preferred protocol for Git operations? HTTPS
? Authenticate Git with your GitHub credentials? Yes
? How would you like to authenticate GitHub CLI? Login with a web browser

! First copy your one-time code: XXXX-XXXX
Press Enter to open github.com in your browser...

✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as your-username
Alternative: SSH key authentication

If you prefer SSH keys over HTTPS, follow GitHub's SSH setup guide. SSH uses key pairs instead of browser-based login, and is common in professional environments.

Connect your local repo to GitHub

GitHub will show you the commands after you create the repo. Here's what they do:

git remote add origin https://github.com/YOUR-USERNAME/nerdsystem-app.git
git branch -M main
git push -u origin main
Verify it worked

Refresh your GitHub repo page. You should see all your files there.

$ git remote add origin https://github.com/your-user/nerdsystem-app.git
$ git branch -M main
$ git push -u origin main

Enumerating objects: 24, done.
Counting objects: 100% (24/24), done.
Delta compression using up to 8 threads
Compressing objects: 100% (21/21), done.
Writing objects: 100% (24/24), 50.12 KiB | 6.27 MiB/s, done.
Total 24 (delta 0), reused 0 (delta 0)
To https://github.com/your-user/nerdsystem-app.git
* [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

From now on, after making changes, the cycle is just: git add . then git commit -m "message" then git push.

Understanding .gitignore

Not everything should be tracked. The .gitignore file tells Git which files and folders to skip. create-next-app generated one for you — here's what's in it and why:

.gitignore
# dependencies — huge folder, reinstalled from package.json
/node_modules

# build output — regenerated on every build
/.next
/out

# environment variables — contains secrets!
.env
.env.local
.env.production.local
.env.development.local

# debug logs
npm-debug.log*

# editor and OS files
.DS_Store
*.swp

The biggest ones to remember: node_modules/ is massive and reproducible (anyone can run npm install to get it back), and .env* files contain secrets.

Never commit .env files, API keys, database passwords, or any secret to Git. Once something is in your Git history, it's extremely difficult to fully remove — even if you delete the file later. Treat your Git history as public.

Quick Reference

Here's the mental model. Git has three "zones" your code moves through:

  1. Working directory — your files on disk, with unsaved changes
  2. Staging area — changes you've marked for the next commit (git add)
  3. Repository — committed snapshots stored in .git/ (git commit)

And git push copies your repository to GitHub. That's the whole system.

What does 'git add .' do?

Why should you never commit .env files?

What's the purpose of creating a branch?

Troubleshooting common errors

fatal: not a git repository You're running git commands outside your project directory. Make sure you cd into your project folder first:

cd nerdsystem-app
git status

git push rejected (non-fast-forward) Someone (or you, from another machine) pushed changes you don't have locally. Pull first, then push:

git pull --rebase origin main
git push origin main

GitHub authentication failure If git push asks for a password and fails, re-run gh auth login and make sure you selected HTTPS and authenticated via the browser. Check that you're logged in with gh auth status.

Exercise: Create a Feature Branch

Create a new branch called add-about-page, make any small change (like adding a comment to page.tsx), commit it, and push it to GitHub. Then switch back to main.

Show hint

Use git checkout -b add-about-page to create and switch to the new branch. Then git add ., git commit -m "your message", git push -u origin add-about-page, and finally git checkout main to switch back.

Show solution
# Create and switch to new branch
git checkout -b add-about-page
 
# Make a change (e.g., add a comment)
echo "// About page coming soon" >> src/app/page.tsx
 
# Stage, commit, and push
git add src/app/page.tsx
git commit -m "chore: prepare for about page"
git push -u origin add-about-page
 
# Switch back to main
git checkout main

Merging Your Branch

After finishing work on a branch, you need to merge it back into main:

git checkout main
git merge add-about-page

This brings your branch's changes into main. On real projects, you'll open a Pull Request on GitHub instead of merging locally — this lets teammates review your code before it's merged. You can create PRs using the GitHub CLI (gh pr create) or ask Claude Code to do it for you.

Next Up

You've got a project, it's tracked with Git, and it's backed up on GitHub. Now let's talk about the thing that makes this whole course different — how to actually work with AI as your development partner. The next lesson covers the AI-first workflow you'll use for the rest of this course.

PreviousYour First Next.js Project
NextThe AI-First Development Workflow