Git & GitHub Workflow


What is Git?

Git = Distributed version control system for tracking code changes

Key Features:

  • Distributed - Every developer has full history

  • Branching - Easy and fast branch creation

  • Fast - Most operations are local

  • Data Integrity - SHA-1 checksums

  • Non-linear Development - Multiple parallel branches

Git vs GitHub:

  • Git = Version control system (software)

  • GitHub = Web-based hosting service for Git repositories (platform)


Git Installation & Configuration

Installation

Initial Configuration


Git Basics

Creating a Repository

The Three States

Adding Files (Staging)

Committing Changes

Viewing History

Viewing Changes


Branching & Merging

Creating Branches

Switching Branches

Merging Branches

Merge Strategies

Deleting Branches


Resolving Merge Conflicts

When Conflicts Occur

Resolving Conflicts


Working with Remote Repositories

Adding Remotes

Fetching & Pulling

Pushing Changes


Undoing Changes

Unstage Files

Discard Changes

Reverting Commits

Resetting Commits

Reset vs Revert


Stashing Changes

Basic Stashing

Advanced Stashing


Tagging

Creating Tags

Pushing Tags


Git Workflows

Feature Branch Workflow

GitFlow Workflow

Branches:

  • main - Production code

  • develop - Development branch

  • feature/* - New features

  • release/* - Release preparation

  • hotfix/* - Production fixes

GitHub Flow (Simplified)


Rebasing

Basic Rebase

Interactive Rebase

Rebase vs Merge


GitHub Features

Pull Requests (PRs)

Creating a PR:

  1. Push branch to GitHub

  2. Navigate to repository on GitHub

  3. Click "New Pull Request"

  4. Select base and compare branches

  5. Add title and description

  6. Request reviewers

  7. Create pull request

PR Best Practices:

PR Commands:

Code Review

Reviewer Checklist:

  • ✅ Code follows project conventions

  • ✅ Tests are included and pass

  • ✅ No security vulnerabilities

  • ✅ Performance considerations

  • ✅ Documentation updated

  • ✅ No debugging code left

Review Comments:

GitHub Actions (CI/CD)

GitHub Issues

Creating Issues:


.gitignore File

Common .gitignore for .NET


Advanced Git Commands

Cherry-pick

Bisect (Find Bug)

Reflog (Recover Lost Commits)

Cleaning

Blame (Find Who Changed Line)


Git Aliases

Setting Up Aliases

Common Aliases


Git Best Practices

Commit Messages

Format:

Types:

  • feat: New feature

  • fix: Bug fix

  • docs: Documentation changes

  • style: Formatting, missing semicolons, etc.

  • refactor: Code refactoring

  • test: Adding tests

  • chore: Maintenance tasks

Examples:

Branch Naming

Commit Frequency

Before Pushing


Troubleshooting Common Issues

Merge Conflicts

Accidentally Committed to Wrong Branch

Undo Pushed Commit

Recover Deleted Branch

Large Files


Collaboration Best Practices

Pull Request Checklist

Before Creating PR:

PR Description Should Include:

Code Review Guidelines

As Author:

  • Keep PRs small and focused

  • Respond to comments promptly

  • Don't take feedback personally

  • Explain reasoning when disagreeing

As Reviewer:

  • Review promptly (within 24 hours)

  • Be constructive and kind

  • Focus on code, not person

  • Explain why, not just what

  • Approve when requirements met

Merge Strategy


Git Cheat Sheet

Daily Commands

Undoing Things

Remote Operations


Quick Reference: When to Use What

Merge vs Rebase

Scenario
Use Merge
Use Rebase

Feature branch → main

Main → feature branch

Public/shared branch

Private branch

Want clean history

Want full history

Reset vs Revert

Scenario
Use Reset
Use Revert

Local commits only

Pushed commits

Want to preserve history

Want to rewrite history


Guide Complete! This comprehensive Git & GitHub guide covers installation, basic commands, branching strategies, workflows, collaboration, best practices, and troubleshooting. Master Git to collaborate effectively with your team! 🔀

Last updated