Git & GitHub: Complete Guide

Learn version control, collaboration, and workflow best practices

Introduction

Git is a distributed version control system used to track and manage source code. GitHub is a platform for hosting Git repositories online, used for collaboration, issues, pull requests, and project management.

Setup & Configuration

To install Git:

Configure your identity:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Essential Git Commands

Git File Lifecycle

Files move through these stages:

Branching & Merging

Git Stash

Restore & Reset

Rebase vs Merge

Merge: Preserves history and creates a merge commit.

Rebase: Rewrites history for a cleaner, linear timeline.

git rebase main
git merge feature

Git Squash

Combine multiple commits into one:

git rebase -i HEAD~n → Change pick to squash

Tags & Releases

Git Workflows

Git Flow: Uses branches like main, develop, feature/, release/, hotfix/.

GitHub Flow: Create branch → Work → PR → Review → Merge

GitHub Usage

Open Source Contribution

  1. Fork the repo
  2. Create new branch
  3. Make changes and commit
  4. Push to your fork
  5. Create Pull Request (PR)
  6. Get reviewed & merged