Master Git from Zero to Hero

Learn commands, workflows, and IDE integration with our interactive platform

Installation Guide

Installing Git on Windows

  1. Download Git from the official website: https://git-scm.com/download/win
  2. Run the installer and follow the setup wizard
  3. Accept the default settings unless you have specific requirements
  4. Verify installation by opening Command Prompt and typing:
    git --version

Alternative installation using Winget:

winget install --id Git.Git -e --source winget

Installing Git on Mac

  1. Install Homebrew if you haven't already:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Install Git using Homebrew:
    brew install git
  3. Verify installation:
    git --version

Installing Git on Linux

For Debian/Ubuntu-based distributions:

sudo apt update
sudo apt install git

For Red Hat/CentOS/Fedora:

sudo yum install git
# Or for newer versions:
sudo dnf install git

Verify installation:

git --version

Basic Git Workflow

Repository

A Git repository contains all of your project's files and tracks changes to those files over time.

Staging

Add changes to the staging area to prepare them for a commit using git add.

Commit

Save changes to your repository with a descriptive message using git commit.

Branch

Create separate lines of development using git branch and git checkout.

Merge

Combine changes from different branches using git merge.

Push/Pull

Share changes with remote repositories using git push and git pull.

Git Commands

Essential Commands

git init

Initialize a new Git repository

git init

git clone

Copy an existing repository

git clone https://github.com/user/repo.git

git add

Add files to staging area

git add filename.txt
git add .

git commit

Save changes to repository

git commit -m "Descriptive message"

git status

View repository status

git status

git log

View commit history

git log

Advanced Commands

git rebase

Reapply commits on top of another base

git rebase main

git stash

Temporarily save changes

git stash
git stash pop

git cherry-pick

Apply specific commits from another branch

git cherry-pick <commit-hash>

git revert

Undo commits safely

git revert <commit-hash>

git reset

Reset current HEAD to specified state

git reset --hard HEAD~1

git tag

Create tags for releases

git tag v1.0.0
Git Master Terminal

$ Welcome to Git Master Terminal! Try some commands:

$ git init

$ git add .

$ git commit -m "Initial commit"

$

VS Code Integration

Source Control Panel

VS Code has built-in Git support. The Source Control panel shows all changes in your repository.

  • View modified files
  • Stage/unstage changes
  • Commit with message
  • View commit history

Branch Management

Easily switch between branches and create new ones from the status bar.

  • Click on the branch name in the status bar
  • Select existing branch or create new
  • View branch history

Merge Conflicts

VS Code provides visual tools to resolve merge conflicts.

  • Automatic conflict detection
  • Side-by-side comparison
  • Accept incoming/current changes

Advanced Features

Best Practices

  • Write clear, concise commit messages
  • Use feature branches for development
  • Regularly sync with remote repositories
  • Use .gitignore for unnecessary files

Branching Strategies

  • Git Flow: master, develop, feature, release, hotfix
  • GitHub Flow: main branch with feature branches
  • Trunk-based Development: small, frequent commits to main

Git Hooks

Automate tasks with client-side and server-side hooks:

  • pre-commit: validate code before committing
  • post-commit: notify team of changes
  • pre-push: run tests before pushing

CI/CD Integration

Connect Git with continuous integration pipelines:

  • GitHub Actions
  • GitLab CI/CD
  • Jenkins
  • CircleCI

FAQ & Resources

What is Git?

Git is a distributed version control system that tracks changes in files and coordinates work among multiple people.

How is Git different from GitHub?

Git is the version control system, while GitHub is a cloud-based hosting service for Git repositories.

How do I undo the last commit?

Use git reset --soft HEAD~1 to undo the last commit while keeping changes staged.

How do I resolve merge conflicts?

Open conflicting files, edit to resolve differences, then add and commit the resolved files.