What is Git?
Git is a distributed version control system (DVCS) created by Linus Torvalds in 2005 for Linux kernel development. It's now the most widely used version control system in software development.
Key Features
- Distributed architecture (every clone is a full repository)
- Lightweight branching and merging
- Data integrity through SHA-1 hashing
- Non-linear development support
How Git Works
Git takes snapshots of your project at different points in time. Each snapshot (commit) contains:
- Pointer to the previous commit
- Author information
- Commit message
- Hash of the file tree
What is GitHub?
GitHub is a cloud-based platform built around Git that provides:
- Remote repository hosting
- Collaboration tools (issues, pull requests)
- Project management features
- CI/CD integration (GitHub Actions)
- Package registry
GitHub vs Git
While Git is the version control software you run locally, GitHub is a platform that hosts Git repositories in the cloud with additional collaboration features.
Why Use Git & GitHub?
For Individual Developers
- Version history: Track every change and revert when needed
- Experimentation: Create branches to try new ideas safely
- Portfolio: Showcase your work to potential employers
For Teams
- Collaboration: Multiple developers can work simultaneously
- Code review: Pull requests enable peer review
- Conflict resolution: Built-in tools to manage merge conflicts
For Organizations
- Workflow automation: CI/CD pipelines with GitHub Actions
- Access control: Granular permissions management
- Project management: Integrated with issues, milestones, and projects
Getting Started with Git
Installation
Initial Configuration
Basic Git Workflow
- Initialize a new repository or clone an existing one
- Create or modify files in your working directory
- Stage changes you want to commit
- Commit the staged changes with a descriptive message
- Push your commits to a remote repository (like GitHub)
Essential Commands
Branching & Merging
Branches allow you to work on different versions of your code simultaneously. The default branch is typically called main or master.
Branching Strategies
Common workflows include:
- Feature branching: Each new feature gets its own branch
- Git Flow: Formal model with develop, feature, release branches
- GitHub Flow: Simpler model focused on pull requests
GitHub Collaboration Workflow
- Fork the repository (creates your personal copy)
- Clone your fork locally
- Create a feature branch for your changes
- Make changes and commit them
- Push your branch to your fork
- Create a pull request (PR) to propose your changes
- Address any review feedback
- After approval, your changes get merged
GitHub-Specific Commands
Advanced Topics
Undoing Changes
Rebasing
Alternative to merging that creates linear history:
Stashing
Temporarily save changes without committing:
Learning Resources
Official Documentation
Interactive Learning
Books
- Pro Git (free online)
- Git Pocket Guide