GIT Version Control System

βœ… Core Essence of Git

At its heart, Git is a tool to track and manage changes to files over time, especially source code, and it enables multiple developers to collaborate without overwriting each other’s work.

Think of it like a time machine + collaboration manager for your code.

πŸ”„ What Makes Git Special?

1. Distributed

2. Version Tracking

Each "commit" in Git saves:

This enables you to:

3. Branches & Merging

Git makes it easy to:

This supports parallel development, feature testing, and bug fixes.

🧠 Think of Git Like This

🀝 Collaboration

Git enables teamwork via remote repositories like GitHub, GitLab, and Bitbucket. Collaborators can:

πŸ” Git Push, Pull Requests, and Forks

βœ… git push

git push uploads your local commits to a remote repository (like GitHub).

Example:

git push origin main

This pushes your changes to the main branch on the remote named origin.

βœ… Pull Request (PR)

A Pull Request is a request to merge your changes into someone else’s branch or repository. It's used in collaboration workflows for:

Workflow:

  1. You push changes to your branch
  2. Create a pull request on GitHub
  3. Reviewers approve or suggest changes
  4. The branch is merged after review

βœ… Fork

A fork is a personal copy of someone else's repository on GitHub. It allows you to:

Typical Open Source Flow:

  1. Fork the repo on GitHub
  2. Clone it to your machine
  3. Make changes and push to your fork
  4. Create a pull request to the original repo

🧩 Other Git Concepts

βœ… git status

Displays the current state of the working directory and staging area.

git status

βœ… git log

Shows the project's commit history.

git log

Optional flags:

git log --oneline --graph --all

βœ… git diff

Shows differences between files, commits, or branches.

git diff
git diff --staged
git diff HEAD~1

βœ… git clone

Creates a local copy of a remote Git repository.

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

βœ… git rebase

Rewrites the base of a branch by reapplying commits on a new base.

git rebase main

Note: Avoid using on public branches to prevent history conflicts.

βœ… git stash

Temporarily saves changes that are not ready to be committed.

git stash
git stash apply
git stash pop
git stash list

βœ… .gitignore

Used to tell Git to ignore specific files or directories.

Example:

*.log
build/
.env
__pycache__/

🧠 Summary Table

Command/Concept Purpose
git statusShows current working/staging state
git logShows commit history
git diffCompares file changes
git cloneCopies a remote repo to your system
git rebaseRewrites history to apply changes on a new base
git stashSaves uncommitted work temporarily
.gitignoreExcludes files from being tracked

πŸ“Œ Summary

Concept Description
Distributed Everyone has the full project and history
Versioning Every commit saves a state of the project
Branching Parallel development is easy and safe
Merging Combine changes from multiple branches
Collaboration Coordinate changes with multiple developers

πŸ”„ Git vs GitHub

Aspect Git GitHub
What is it?Command-line toolWeb-based platform
RoleVersion control systemHosting and collaboration
Works offline?YesNo
FunctionalityTracking changes, branching, mergingPRs, Issues, CI/CD, team work
Installation needed?YesNo (browser-based)
Examplesgit commit, git mergeGitHub PRs, Actions, Issues

Analogy: Git is the engine of your car. GitHub is the garage and road system to drive and collaborate with others.