Getting Started
Git transforms version control from a chore into a strategic tool for managing code evolution. This section establishes the foundational skills necessary for effective Git usage—from initial configuration through basic collaborative workflows.
Understanding these fundamentals enables confident progression to more advanced techniques. Each concept builds systematically: configuration establishes your development identity, repository initialization creates the version control structure, and the basic workflow demonstrates Git’s three-stage architecture. These patterns recur throughout all Git operations.
What You’ll Learn
This section covers the essential operations that constitute 90% of daily Git usage. Mastering these commands provides a stable foundation for understanding Git’s design philosophy and more complex workflows.
Core Skills Covered:
- Global configuration and identity management
- Repository creation and cloning strategies
- The three-stage workflow: working directory → staging area → repository
- Branch creation and navigation
- Remote repository interaction patterns
- File exclusion with
.gitignore
Time Investment: 30-45 minutes for initial setup and basic operations. Competence develops through regular practice over several weeks of daily development work.
Learning Path
Setup & Configuration
Purpose: Establish your development identity and configure Git’s behavior across all repositories.
Every commit records authorship information—proper configuration ensures accurate attribution. Beyond identity, configuration controls line ending handling (critical for cross-platform teams), default editor integration, and operational preferences.
Key Operations:
- Identity configuration:
user.nameanduser.email - Editor integration for commit messages
- Cross-platform line ending management with
core.autocrlf - Repository-wide enforcement via
.gitattributes
Common Pitfall: Inconsistent line endings cause “entire file changed” problems in diffs, particularly when collaborating across Windows, Mac, and Linux environments.
Initialize & Clone
Purpose: Create new version-controlled repositories or obtain local copies of existing projects.
Two entry points exist for working with Git repositories: initialization creates new repositories for projects not yet under version control, while cloning creates local replicas of existing remote repositories—the standard workflow when joining projects.
Key Operations:
git init: Transform a directory into a Git repositorygit clone: Replicate remote repositories locally with complete history
When to Use Which:
- Initialize: Starting a new project, converting legacy code to Git
- Clone: Joining existing projects, deploying code, setting up development environments
Basic Workflow
Purpose: Master Git’s fundamental three-stage architecture for tracking and recording changes.
Git’s staging area (the “index”) distinguishes it from traditional version control systems. This intermediate layer enables precise commit composition—selecting specific changes from your working directory to form logical, reviewable commits even when working on multiple features simultaneously.
The Three States:
- Working Directory: Current file modifications
- Staging Area: Changes selected for the next commit
- Repository: Committed snapshots in project history
Key Operations:
git status: Inspect current state across all three stagesgit add: Promote changes from working directory to staging areagit commit: Record staged changes as permanent history- Interactive staging with
git add -p: Select specific changes within files
Critical Understanding: Commits capture only staged content, not all working directory modifications. This separation enables granular control over commit composition.
Branches
Purpose: Create isolated development contexts for features, experiments, and parallel workflows.
Branches represent Git’s killer feature—enabling concurrent work streams without mutual interference. Unlike traditional version control systems where branching incurs significant overhead, Git’s branch implementation is lightweight (just a pointer to a commit), making branch creation and switching near-instantaneous.
Mental Model: Branches are movable labels pointing to specific commits in the repository’s directed acyclic graph. Creating a branch doesn’t copy files—it creates a new pointer.
Key Operations:
git branch: List existing branchesgit switch -c <name>: Create and switch to new branchgit switch <name>: Navigate between existing branches
Modern Command Syntax: This guide uses git switch rather than the legacy
git checkout, which conflates branch switching with several unrelated
operations. The modern command provides clearer semantics.
Remote Operations
Purpose: Synchronize local repository changes with remote repositories for collaboration and backup.
Git’s distributed architecture means every clone contains complete repository history. Remotes represent connections to other repository instances—typically centralized hosting services like GitHub, GitLab, or Bitbucket, though any Git-accessible repository can serve as a remote.
Key Operations:
git remote: Manage remote repository connectionsgit fetch: Download remote changes without integrating themgit pull: Fetch and merge remote changes into current branchgit push: Upload local commits to remote repository
Critical Distinction: fetch retrieves changes for inspection without
modifying your working directory, while pull performs fetch followed by
immediate merge. Understanding this distinction prevents unexpected working
directory modifications.
Ignoring Files
Purpose: Exclude generated files, build artifacts, and sensitive data from version control.
Not everything in your working directory belongs in Git. Build outputs,
dependency directories, IDE configuration, and sensitive credentials should
remain local. The .gitignore file specifies exclusion patterns, preventing
accidental commits of inappropriate content.
Common Exclusions:
- Build artifacts:
dist/,build/,*.o,*.pyc - Dependency directories:
node_modules/,venv/,vendor/ - IDE configuration:
.vscode/,.idea/,*.swp - Operating system files:
.DS_Store,Thumbs.db - Environment-specific configuration:
.env,config.local.js
Best Practice: Commit .gitignore to the repository so all collaborators
benefit from consistent exclusion rules.
Aliases
Purpose: Create custom shortcuts for frequently-used Git commands, reducing repetitive typing and encoding workflow patterns.
Git aliases transform verbose command sequences into concise invocations through configuration-based expansion. Beyond simple abbreviation, aliases enable workflow optimization by capturing complex parameter combinations and multi-step operations as memorable shortcuts.
Key Operations:
- Define simple command shortcuts:
git config --global alias.st 'status' - Encode parameter combinations:
git config --global alias.unstage 'reset HEAD --'
Next Steps
After mastering these fundamentals, progress to Everyday Git for daily workflow operations like viewing history, undoing changes, stashing work in progress, and managing tags. The Core Concepts section provides deeper understanding of Git’s internal architecture, while Advanced covers power-user techniques for complex operations.
Learning Philosophy: Git rewards incremental mastery. These basics cover the majority of daily operations. Advanced techniques become relevant as project complexity increases—don’t feel pressured to learn everything immediately.