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

1

Create Feature Branch

git checkout -b feature/user-authentication

2

Make Changes and Commit

git add . && git commit -m "Add login functionality"

3

Push to Remote

git push origin feature/user-authentication

4

Create Pull Request

Open PR on GitHub/GitLab for code review

5

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

1

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

2

Add Files

git add .

Stage files for commit (prepare them to be saved)

When to use: After making changes you want to save

3

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

4

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.

5

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

6

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.

AspectGitGitHub
What it isVersion control system (software)Cloud hosting service for Git repositories
InstallationInstall on your computerAccess through web browser
UsageCommand line tool for version controlWeb interface + Git functionality
StorageLocal repositories on your machineRemote repositories in the cloud
CollaborationBasic merging and branchingPull requests, issues, project management
CostFree and open sourceFree for public repos, paid for private

Git Hosting Platforms Comparison

GitHub

The world's largest code hosting platform

Features:

Public/private reposActions CI/CDIssues & PRsGitHub Pages

Best For:

Open source projects, collaboration, portfolio

Pricing:

Free for public repos, paid for private

Visit Platform

GitLab

Complete DevOps platform with built-in CI/CD

Features:

Integrated CI/CDIssue trackingWikiContainer registry

Best For:

Enterprise teams, complete DevOps workflow

Pricing:

Free tier available, paid for advanced features

Visit Platform

Bitbucket

Atlassian's Git solution integrated with Jira

Features:

Jira integrationPipelinesPull requestsCode insights

Best For:

Teams using Atlassian tools, enterprise

Pricing:

Free for small teams, paid for larger teams

Visit Platform

Azure DevOps

Microsoft's comprehensive DevOps platform

Features:

Azure ReposAzure PipelinesWork itemsTest plans

Best For:

Microsoft ecosystem, enterprise development

Pricing:

Free for small teams, paid for additional features

Visit Platform

SourceForge

One of the oldest code hosting platforms

Features:

Project hostingDownload statisticsTicketingForums

Best For:

Open source projects, legacy projects

Pricing:

Free for open source projects

Visit Platform

Codeberg

Non-profit Git hosting focused on privacy

Features:

Privflex flex-col gap-3focusedNo trackingOpen sourceCommunity-driven

Best For:

Privflex flex-col gap-3conscious developers, open source

Pricing:

Completely free

Visit Platform

Git Learning Resources

Interactive Learning

Learn Git Branching

Visual and interactive Git tutorial

Visit Resource →

Git Immersion

Guided tour through Git fundamentals

Visit Resource →

GitHub Skills

Hands-on courses for GitHub

Visit Resource →

Atlassian Git Tutorials

Comprehensive Git tutorials

Visit Resource →

Documentation & References

Pro Git Book

Complete Git reference (free online)

Visit Resource →

Git Official Documentation

Official Git command reference

Visit Resource →

GitHub Docs

Complete GitHub documentation

Visit Resource →

GitLab Docs

GitLab user and admin documentation

Visit Resource →

Tools & Utilities

Git Cheat Sheet

Quick reference for Git commands

Visit Resource →

Gitignore.io

Generate .gitignore files for your projects

Visit Resource →

Git Kraken

Visual Git client with GUI

Visit Resource →

SourceTree

Free Git GUI for Windows and Mac

Visit Resource →

✅ 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