{"post":{"slug":"what-is-git-basics-2026","title":"What is Git: basics explained for 2026","excerpt":"Git is the version control system that every developer needs to understand. This guide covers the core concepts, essential commands, and the mental model that makes Git click.","category":"code","date":"April 8, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">G</span>it is the distributed version control system used by virtually every software team in the world. Created by Linus Torvalds in 2005 to manage the Linux kernel, it became the universal standard for tracking code changes, coordinating teams, and shipping software safely. In 2026, understanding Git is not optional — it is the baseline expectation for every developer role.\n\n## What changed in 2026\n\n- **GitHub Copilot and AI tools integrate with Git.** AI assistants now summarize diffs, suggest commit messages, and explain merge conflicts in plain language. The underlying Git concepts remain the same; the tooling got friendlier.\n- **Trunk-based development is the dominant workflow.** Long-lived feature branches are rarer in high-performing teams; short-lived branches merged daily into `main` with feature flags are the norm.\n- **Merge queues are standard on GitHub and GitLab.** Protected branches with merge queues serialize merges and re-run CI against the merged result, eliminating the \"passed CI but broke main\" problem.\n- **Git 2.45+ improvements.** Sparse checkout, partial clone, and `git maintenance` became polished features. Large monorepos use sparse checkout to check out only the directories they need.\n\n## The mental model: three areas\n\n```\nWorking Directory    →  Staging Area  →  Repository\n(your file edits)       (git add)         (git commit)\n\n                                        ↕ push / pull\n                                      Remote Repository\n                                       (GitHub, GitLab)\n```\n\n**Working directory:** your files as they exist on disk. You edit them freely.\n\n**Staging area (index):** a holding area where you select which changes to include in the next commit. This is what makes Git powerful — you can commit part of your changes, not all of them.\n\n**Repository (.git directory):** the full history of committed snapshots.\n\n## Core commands you use every day\n\n```bash\n# Check what changed\ngit status                  # what is staged, what is not, untracked files\ngit diff                    # unstaged changes\ngit diff --staged           # staged changes (what will be in next commit)\n\n# Record changes\ngit add file.py             # stage a specific file\ngit add -p                  # interactively stage hunks (not whole files)\ngit commit -m \"add user creation endpoint\"\n\n# Undo things\ngit restore file.py         # discard unstaged changes to a file\ngit restore --staged file.py  # unstage (keep changes in working dir)\n\n# Branching\ngit branch feature/login    # create branch\ngit switch feature/login    # switch to it\ngit switch -c feature/login # create AND switch (common shortcut)\n\n# Merging / rebasing\ngit merge feature/login     # merge into current branch\ngit rebase main             # replay your branch on top of main\n\n# Remote operations\ngit push origin feature/login\ngit pull                    # fetch + merge (or fetch + rebase if configured)\ngit fetch                   # download remote changes without merging\n```\n\n## How commits work\n\nA commit is a snapshot — not a diff. Git stores the complete state of every tracked file at the moment of commit. When you ask for a diff between two commits, Git computes it by comparing snapshots.\n\n```bash\ngit log --oneline         # one line per commit\n# output:\n# a3f91c2 add password reset endpoint\n# 88d3e01 add user creation endpoint\n# 4f2b110 initial commit\n\ngit show a3f91c2          # show the commit: message + diff from parent\ngit log --graph --oneline # ASCII graph of branch topology\n```\n\nEach commit contains: a pointer to the snapshot (tree), a pointer to its parent commit(s), the author, the committer, the timestamp, and the commit message. The commit hash (SHA-1) is computed from all of this — change any part, and you get a different hash.\n\n## Branching and merging\n\n```bash\n# Common branch workflow\ngit switch main\ngit pull                          # get latest\ngit switch -c feature/payment     # new branch from main\n\n# ... make changes, add, commit ...\n\ngit switch main\ngit pull                          # get any changes that landed while you worked\ngit merge feature/payment         # merge your branch\n\n# or via pull request (more common):\ngit push origin feature/payment   # push branch to remote\n# open PR on GitHub → review → merge → delete branch\n```\n\n**Merge vs rebase:**\n\n| Method | Result | When to use |\n| --- | --- | --- |\n| `git merge` | Preserves branch history with a merge commit | Shared branches, PRs |\n| `git rebase` | Replays commits on top of target; linear history | Local cleanup before PR |\n| `git squash merge` | Combines all PR commits into one | Keeping main history clean |\n\n## How to pick a branching strategy\n\n| Strategy | Best for | Characteristics |\n| --- | --- | --- |\n| Trunk-based development | High-deployment-frequency teams | Short branches, feature flags, CI on main |\n| GitHub flow | Most teams | One main branch, feature branches, PRs |\n| GitFlow | Versioned releases, long support cycles | develop, main, release, hotfix branches |\n\nMost teams doing continuous delivery use GitHub Flow or trunk-based development. GitFlow is appropriate for software with explicit versioned releases (libraries, mobile apps with app store delays).\n\n## The four things that go wrong and how to fix them\n\n**1. Committed to the wrong branch:**\n```bash\ngit log --oneline -3    # note the commit hash\ngit switch correct-branch\ngit cherry-pick <hash>  # apply that commit to this branch\ngit switch wrong-branch\ngit reset HEAD~1        # remove last commit from wrong branch (keeps changes)\n```\n\n**2. Merge conflict:**\n```\n<<<<<<< HEAD\nreturn calculate_v1(amount)\n=======\nreturn calculate_v2(amount, currency)\n>>>>>>> feature/currency\n```\nEdit the file to keep what you want, remove the markers, then `git add` and `git commit`.\n\n**3. Accidentally staged a file with secrets:**\n```bash\ngit restore --staged .env    # unstage it\necho \".env\" >> .gitignore    # make sure it is ignored going forward\n```\n\n**4. Need to undo the last commit (not yet pushed):**\n```bash\ngit reset HEAD~1    # undo commit, keep changes staged\ngit reset HEAD~1 --soft   # same\ngit reset HEAD~1 --mixed  # undo commit, unstage changes (default)\n```\n\n## Common mistakes\n\n**Writing uninformative commit messages.** \"fix bug\" or \"wip\" tells future-you and your team nothing. Write a message that explains *what* changed and *why*.\n\n**Giant commits.** A commit with 40 changed files across 5 features is hard to review and impossible to bisect when something breaks. Commit small, focused changes.\n\n**Committing secrets.** Once a secret is in Git history, it is compromised — even if you delete the file in the next commit. Use `.gitignore`, environment variables, and a secret scanner in CI.\n\n**Merging instead of rebasing in local cleanup.** Before opening a PR, rebase your branch on main so the reviewer sees a clean linear history. Save merges for the actual integration.\n\n## What to skip\n\n- **Force-pushing to main or shared branches** — this rewrites history and causes confusion for everyone who has pulled the branch.\n- **Long-lived feature branches** — the longer a branch lives, the worse the merge conflict. Aim to merge within 1–2 days.\n- **Storing large binary files in Git** — use Git LFS (Large File Storage) for large assets. Plain Git handles binary files poorly.\n\n## FAQ\n\n**What is the difference between git pull and git fetch?**\n`git fetch` downloads remote changes to your local copy of the remote branch but does not modify your working directory or local branches. `git pull` is `git fetch` followed by `git merge` (or `git rebase` if configured). Use `git fetch` when you want to see what changed before deciding what to do.\n\n**What is HEAD?**\nHEAD is a pointer to your current position in the repository — usually the latest commit on your current branch. When you switch branches, HEAD moves. \"Detached HEAD\" means HEAD points to a specific commit, not a branch.\n\n**What is the difference between git reset and git revert?**\n`git reset` moves the branch pointer backward, rewriting history. `git revert` creates a new commit that undoes a previous commit, preserving history. Use `git revert` on shared branches; use `git reset` only on local, unpushed commits.\n\n**How do I find who changed a specific line?**\n`git blame <file>` annotates each line with the commit and author that last changed it. `git log -S \"search string\" --oneline` finds commits that added or removed a specific string.\n\n## Where to go next\n\n- [How to write good commit messages in 2026](/blog/how-to-write-good-commit-messages-2026)\n- [How to deploy with GitHub Actions in 2026](/blog/how-to-deploy-with-github-actions-2026)\n- [How to review a pull request in 2026](/blog/how-to-review-a-pull-request-2026)","hue":314,"metaTitle":"What Is Git: Basics Explained for 2026","metaDescription":"Learn Git basics in 2026. Covers commits, branches, merging, remotes, and the mental model that makes Git commands predictable.","keywords":["what is git 2026","git basics explained 2026","git tutorial beginners 2026","git commit branch merge explained","git commands cheat sheet 2026","git mental model","git remote origin explained","git staging area explained","git workflow 2026","version control git 2026"],"tldr":["**Git tracks snapshots, not diffs** — each commit stores a complete snapshot of your project; Git computes diffs on demand from these snapshots.","**The three areas: working directory, staging area, repository** — you edit in the working directory, stage changes deliberately, then commit to the repo.","**Branching is cheap and fast** — a branch is just a pointer to a commit; create and delete them freely without fear.","**Remote is just another copy** — origin is a convention, not a special place; push sends your commits there, pull (or fetch + merge) brings theirs to you.","**Skip:** force-pushing to a shared branch — it rewrites history that other people have built on and causes serious merge pain."],"readTime":"6 min read","wordCount":1383},"related":[{"slug":"how-to-use-git-and-github-2026","title":"How to Use Git and GitHub in 2026: a starter guide","excerpt":"Git tracks your code history; GitHub hosts it online. This 2026 guide covers the core commands and workflow you actually need to start using both today.","category":"code","date":"May 23, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":240},{"slug":"what-is-git-2026","title":"What Is Git in 2026: a beginner-friendly guide","excerpt":"Git is a tool that tracks every change to your code, lets you undo mistakes, and lets many people work on the same project without overwriting each other.","category":"code","date":"May 25, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":195},{"slug":"what-is-a-git-commit-2026","title":"What Is a Git Commit in 2026: snapshots explained","excerpt":"A Git commit is a saved snapshot of your project at one moment, paired with a message describing the change, that forms the permanent history you can return to or compare against.","category":"code","date":"June 17, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":210}],"sameCategory":[{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145},{"slug":"graphql-federation-2026","title":"GraphQL Federation: One Graph, Many Teams","excerpt":"Federation composes independently-owned subgraphs into a single API. Here is what it solves, the operational cost it adds, and when a simpler gateway is enough.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":300},{"slug":"hermetic-builds-explained-2026","title":"Hermetic Builds Explained: Same Inputs, Same Output","excerpt":"A hermetic build depends only on declared inputs. Here is what that property gives you, the common leaks that break it, and how to move toward it incrementally.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":130},{"slug":"monorepo-tooling-compared-2026","title":"Monorepo Tooling Compared: What You Actually Need","excerpt":"Monorepo tools solve task orchestration and caching, not repository layout. Here is what each tier provides and how to tell when you have outgrown the simple option.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":150}],"newer":{"slug":"what-is-dollar-cost-averaging-2026","title":"What is dollar cost averaging in 2026: how it works and when to use it","excerpt":"Dollar cost averaging removes the hardest decision in investing — when to buy. Here is how it works, the math behind it, and when it beats lump-sum investing.","category":"finance","date":"April 8, 2026","author":"ByteLedger Team","readTime":"5 min read","hue":300},"older":{"slug":"what-is-liquidity-2026","title":"What is liquidity in 2026? Why access to cash matters as much as returns","excerpt":"Liquidity measures how quickly you can convert an asset to cash without a significant loss in value. Here is why it belongs at the center of your financial plan.","category":"finance","date":"April 8, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":316}}