Git
Git is a distributed version control system that tracks changes in files and coordinates work among multiple developers. Unlike centralized systems, Git maintains a complete history of your project locally, allowing you to work offline and providing robust backup capabilities. The distinction between local (your machine) and remote (servers like GitHub) repositories is fundamental - you work locally and synchronize with remote repositories when ready.
Branching is one of Git's most powerful features, allowing you to create separate lines of development for different features or experiments. GitHub extends Git's capabilities by providing a web-based platform for hosting repositories, collaboration tools, issue tracking, and continuous integration workflows.
Basic Git Workflow
Checking Status
Shows the current state of your working directory and staging area, displaying which files are modified, staged, or untracked.Adding Changes
git add filename.txt # Add specific file
git add . # Add all changes in current directory
git add -A # Add all changes in repository
Committing Changes
Creates a snapshot of your staged changes with a descriptive message explaining what was changed and why.Synchronizing with Remote
Pulling with Rebase
Fetches changes from the remote repository and replays your local commits on top of the updated branch. This creates a cleaner, linear history compared to merge commits and is often preferred in collaborative workflows.The rebase approach: - Fetches the latest changes from remote - Temporarily removes your local commits - Applies the remote changes - Replays your commits on top
Ignoring Files
.gitignore
Create a .gitignore file in your repository root to specify files and directories that Git should ignore:
# Dependencies
node_modules/
*.log
# Build outputs
dist/
build/
# Environment files
.env
.env.local
# IDE files
.vscode/
*.swp
# OS files
.DS_Store
Thumbs.db
Patterns in .gitignore:
- *.log ignores all .log files
- temp/ ignores the temp directory
- !important.log includes important.log even if *.log is ignored
- Use # for comments