# Git Git is an open source [[Distributed Version Control System (DVCS)]], also known as a [[Source Control Management (SCM)]] system. Created by [[Linus Torvalds]] in 2005 for Linux kernel development, it has become the dominant version control system for software development. Git tracks changes to files over time, enabling collaboration, branching, merging, and maintaining a complete history of a project. ## Key Concepts - **Repository (repo)**: A directory containing your project and its complete history - **Commit**: A snapshot of changes at a point in time - **Branch**: An independent line of development - **Merge**: Combining changes from different branches - **Remote**: A version of the repository hosted elsewhere (GitHub, GitLab, etc.) - **Clone**: Creating a local copy of a remote repository - **Pull/Push**: Syncing changes between local and remote ## Why Git Dominates - **Distributed**: Every clone is a full repository with complete history - **Fast**: Most operations are local, no network required - **Branching**: Lightweight branches encourage experimentation - **Data integrity**: SHA-1 hashes ensure content integrity - **Staging area**: Fine-grained control over what gets committed ## Essential Commands | Command | Description | |---------|-------------| | `git init` | Initialize a new repository | | `git clone <url>` | Clone a remote repository | | `git add <file>` | Stage changes for commit | | `git commit -m "msg"` | Create a commit with message | | `git push` | Upload local commits to remote | | `git pull` | Download and merge remote changes | | `git branch` | List, create, or delete branches | | `git checkout <branch>` | Switch branches | | `git merge <branch>` | Merge a branch into current branch | | `git log` | View commit history | | `git status` | Show working tree status | | `git diff` | Show changes between commits | ## Data Model Git uses a [[Directed Acyclic Graph (DAG)]] to track commits. Each commit points to its parent(s), enabling: - Linear history (single parent) - Branching (commits diverge) - Merging (multiple parents) ## Git on Different Platforms - **[[Linux]]/macOS**: Native command line - **Windows**: [[Git Bash]] provides Unix-like experience - **GUI clients**: [[GitKraken]], SourceTree, GitHub Desktop - **CLI clients**: [[LazyGit]] ## Config-Based Hooks (Git 2.54+) Git 2.54 introduced configuration-based hooks, eliminating the need for third-party tools like Husky or pre-commit. Hooks can now be defined in any git config file: ```ini [hook "linter"] event = pre-commit command = ~/bin/linter --cpp20 ``` This works in `~/.gitconfig` (all repos), `/etc/gitconfig` (system-wide), or a repo's local config. Multiple hooks per event are supported and run in order. Legacy scripts in `.git/hooks/` still work and run last. Management commands: - `git hook list <event>` — see all configured hooks and their source - `hook.<name>.enabled = false` — disable without deleting See: [[2026-05-04 Git 2.54 - Config-Based Hooks Replace Husky and Pre-Commit]] ## References - Official website: https://git-scm.com - Pro Git book: https://git-scm.com/book - https://en.wikipedia.org/wiki/Git ## Related - [[Git Bash]] - [[GitKraken]] - [[2026-05-04 Git 2.54 - Config-Based Hooks Replace Husky and Pre-Commit]] - [[GitHub]] - [[GitLab]] - [[Directed Acyclic Graph (DAG)]] - [[Command Line Interface (CLI)]] - [[LazyGit]]