Version Control (Git)
Master Git, the essential version control system for tracking changes, collaborating with teams, and managing your code history effectively.
🌳 What is Git?
Git is a distributed version control system that tracks changes in your code over time. It allows multiple developers to work on the same project simultaneously while maintaining a complete history of all changes.
Why Use Git?
- • Track every change to your code
- • Collaborate safely with team members
- • Revert to previous versions easily
- • Work on features in isolation (branches)
- • Backup your code in multiple locations
Key Benefits:
- • Distributed (works offline)
- • Fast and lightweight
- • Industry standard
- • Powerful branching and merging
- • Complete project history
Core Git Concepts
Repository
A project folder tracked by Git with complete history
Commits
Snapshots of your code at specific points in time
Branches
Parallel versions of your code for different features
Collaboration
Work with teams using push, pull, and merge operations
Essential Git Commands
🚀 Getting Started
# Configure Git (first time setup) git config --global user.name "Your Name" git config --global user.email "your.email@example.com" # Initialize a new repository git init # Clone an existing repository git clone https://github.com/username/repository.git # Check repository status git status # Add files to staging area git add filename.txt # Add specific file git add . # Add all files git add *.js # Add all JavaScript files # Commit changes git commit -m "Add new feature" git commit -am "Add and commit in one step" # View commit history git log git log --oneline # Compact view git log --graph # Visual branch representation
Branching and Merging
🌿 Working with Branches
# List branches git branch # Local branches git branch -r # Remote branches git branch -a # All branches # Create and switch to new branch git checkout -b feature-branch git switch -c feature-branch # Modern alternative # Switch between branches git checkout main git switch main # Modern alternative # Merge branch into current branch git merge feature-branch # Delete branch git branch -d feature-branch # Safe delete git branch -D feature-branch # Force delete # Push branch to remote git push origin feature-branch # Pull latest changes git pull origin main
Common Git Workflow
📋 Feature Branch Workflow
Create Feature Branch
git checkout -b feature/user-authentication
Make Changes and Commit
git add . && git commit -m "Add login functionality"
Push to Remote
git push origin feature/user-authentication
Create Pull Request
Open PR on GitHub/GitLab for code review
Merge and Clean Up
git checkout main && git pull && git branch -d feature/user-authentication
How to Use Git: Step-by-Step Guide
🚀 Basic Git Workflow
Initialize Repository
git init
Create a new Git repository in your project folder
When to use: Starting a new project or adding Git to existing project
Add Files
git add .
Stage files for commit (prepare them to be saved)
When to use: After making changes you want to save
Commit Changes
git commit -m "message"
Save staged changes with a descriptive message
When to use: When you want to create a checkpoint of your work
Connect to Remote
git remote add origin <url>
Link your local repository to a remote repository
When to use: First time connecting to GitHub/GitLab/etc.
Push Changes
git push origin main
Upload your commits to the remote repository
When to use: When you want to backup or share your changes
Pull Changes
git pull origin main
Download and merge changes from remote repository
When to use: Before starting work or when others have made changes
Git vs GitHub: Understanding the Difference
🤔 Common Confusion Explained
Many beginners confuse Git and GitHub. Here's the key difference: Git is the tool, GitHub is the service.
Aspect | Git | GitHub |
---|---|---|
What it is | Version control system (software) | Cloud hosting service for Git repositories |
Installation | Install on your computer | Access through web browser |
Usage | Command line tool for version control | Web interface + Git functionality |
Storage | Local repositories on your machine | Remote repositories in the cloud |
Collaboration | Basic merging and branching | Pull requests, issues, project management |
Cost | Free and open source | Free for public repos, paid for private |
Git Hosting Platforms Comparison
GitHub
The world's largest code hosting platform
Features:
Best For:
Open source projects, collaboration, portfolio
Pricing:
Free for public repos, paid for private
GitLab
Complete DevOps platform with built-in CI/CD
Features:
Best For:
Enterprise teams, complete DevOps workflow
Pricing:
Free tier available, paid for advanced features
Bitbucket
Atlassian's Git solution integrated with Jira
Features:
Best For:
Teams using Atlassian tools, enterprise
Pricing:
Free for small teams, paid for larger teams
Azure DevOps
Microsoft's comprehensive DevOps platform
Features:
Best For:
Microsoft ecosystem, enterprise development
Pricing:
Free for small teams, paid for additional features
SourceForge
One of the oldest code hosting platforms
Features:
Best For:
Open source projects, legacy projects
Pricing:
Free for open source projects
Codeberg
Non-profit Git hosting focused on privacy
Features:
Best For:
Privflex flex-col gap-3conscious developers, open source
Pricing:
Completely free
Git Learning Resources
Interactive Learning
Documentation & References
Tools & Utilities
✅ Git Best Practices
Commit Messages:
- • Use present tense ("Add feature" not "Added feature")
- • Keep first line under 50 characters
- • Be descriptive and specific
- • Reference issue numbers when applicable
Branching:
- • Use descriptive branch names
- • Keep branches focused on single features
- • Delete merged branches
- • Regularly sync with main branch
Collaboration:
- • Always pull before pushing
- • Use pull requests for code review
- • Don't commit directly to main branch
- • Communicate with your team
Security:
- • Never commit passwords or API keys
- • Use .gitignore for sensitive files
- • Enable two-factor authentication
- • Review public repository contents
📚 Git Learning Resources
Interactive Learning:
- • Learn Git Branching (interactive tutorial)
- • GitHub Skills (hands-on courses)
- • Git Immersion (step-by-step walkthrough)
- • Atlassian Git Tutorials
Documentation & Books:
- • Pro Git Book (free online)
- • Git Official Documentation
- • GitHub Docs
- • Git Cheat Sheets