Git & GitHub Tutorial

Rahul's Profile

Git Introduction

What is Git?

Git is a distributed version control system that lets developers track changes in their codebase, collaborate efficiently, and roll back if necessary.

Core Git Concepts

  • Repository: A dedicated folder where Git manages your project's files along with its complete history.
  • Clone: Creating a local copy of a remote repository on your machine to work with.
  • Stage: Selecting specific changes you want Git to prepare for committing, acting as a preparation step.
  • Commit: Recording a snapshot of your staged changes into the repository for historical tracking.
  • Branch: Diverging from the main codebase to work on different features or versions independently.
  • Merge: Combining changes from separate branches back into a single, unified branch.
  • Pull: Fetching and integrating updates from a remote repository to keep your local version current.
  • Push: Sending your committed changes from your local machine to a remote repository for sharing and backup.

Working with Git

  • Start by initializing Git in any folder, which turns it into a repository. Git creates a hidden folder to manage all change history.
  • When you modify, add, or delete files, they are labeled as "modified" in Git.
  • Next, you need to select these changed files for the next snapshot—this is called "staging."
  • Staged files are then committed by Git, capturing a permanent version of the current state.
  • Git keeps a detailed history of every commit, allowing you to review what changes were made and when.
  • You can also reverse to any previous commit if needed, restoring your project to an earlier state.
  • Instead of copying entire files with each commit, Git tracks incremental changes, making version control efficient.

Basic Git Workflow

  1. Initialize a repository: git init
  2. Track files: git add filename or git add .
  3. Commit changes: git commit -m "message"
  4. View history: git log

Common Git Commands

  • git status – Show current changes and status
  • git diff – Show file differences
  • git clone <repo-url> – Copy a repository
  • git push – Upload local commits to remote
  • git pull – Fetch and merge from remote