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:
- Working directory — The current state of files on disk
- Staging area (index) — Changes selected for the next commit
- 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 repositorygit add→git commit→git push— The standard commit workflowgit status— Inspect the current state of the working tree- Branches isolate feature development from the main branch