Dev Basics Lesson 2 of 3

Git Basics

Overview

Git is a distributed version control system that tracks changes to source code over time. GitHub provides remote hosting for Git repositories. Both are integral to modern development workflows, and Claude Code interacts with Git directly during operation.

Prerequisites

Setup: Install Git from git-scm.com and create a GitHub account.

Repository Initialization

Clone an existing repository

git clone https://github.com/user/repo.git

Creates a local copy of a remote repository.

Initialize a new repository

git init

Creates a new Git repository in the current directory.

The Three-Stage Workflow

Git operations proceed through three distinct areas:

  1. Working directory — The current state of files on disk
  2. Staging area (index) — Changes selected for the next commit
  3. Repository — The permanent commit history

Inspect current state

git status

Stage changes

git add filename.js    # Stage a specific file
git add .              # Stage all modifications

Record a commit

git commit -m "Add login feature"

Push to remote

git push

Branch Management

Branches provide isolated development contexts, enabling parallel work without affecting the main codebase.

git branch feature-name    # Create a branch
git checkout feature-name  # Switch to a branch
git checkout -b new-branch # Create and switch in one step

Synchronization: Execute git pull before beginning work to incorporate the latest remote changes.

Key Takeaways

  • git clone — Create a local copy of a remote repository
  • git addgit commitgit push — The standard commit workflow
  • git status — Inspect the current state of the working tree
  • Branches isolate feature development from the main branch