Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Git

Direct answer

Git is the distributed version control system: repositories with commits, branches and remotes; used for code, configuration and infrastructure-as-code.

When to use this

Use it to track changes to scripts and configuration, or when a pull, merge or push fails.

First 30 seconds

1. git status — clean? On which branch?

2. git fetch then git log --oneline --graph -10 --all.

3. Conflicts → resolve, git add, git commit.

4. Rejected push → pull/rebase first.

5. Secrets committed → rotate and rewrite history.

Operational verification

edit → stage → commit → push → review → merge

Evidence · next step

For Software & Source → Git, continue with the first unproven Topic check: Record repository origin and exact commit hash used for the build. If that boundary is healthy, advance to the adjacent check: Inspect working tree/index plus submodule state and generated/untracked inputs that can affect output. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it to track changes to scripts and configuration, or when a pull, merge or push fails.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

7 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

repository/remote identity → fetch/object availability → ref resolution → HEAD commit → working tree/index/submodules → build input snapshot → artifact

Healthy evidence: the expected repository and commit are checked out, the working tree/submodules match the intended source state, and the build records that immutable identity

Step 2 Verification and output interpretation Verify boundary

Verification path. For Git/build issues, record commit/ref, working tree, exact dependency/toolchain versions and the produced binary/library linkage.

Existing fast checks for this Topic. - Record repository origin and exact commit hash used for the build.

  • Inspect working tree/index plus submodule state and generated/untracked inputs that can affect output.
  • Pass the immutable source identity into build/release metadata where possible.
  • Verify the resulting artifact and workload rather than treating checkout success as completion.

Verification chain. repository/remote identity → fetch/object availability → ref resolution → HEAD commit → working tree/index/submodules → build input snapshot → artifact

Step 3 Specialized verification Verify boundary

Record repository path, HEAD commit, branch/upstream, working-tree/index status and remote URLs before changing anything. Fetch to update remote-tracking refs, then compare commits explicitly instead of assuming origin/main is current. For deployment questions, compare the running artifact/service to the intended commit—not merely the source checkout. After merge/rebase/reset, verify history graph, working tree and application/build result. reflog can aid recovery but should not be treated as permanent backup.

Step 4 Commands Verify boundary
git status
git log --oneline -5
git config --global user.name
Step 5 Failure modes and next checks Narrow the fault

Suspicious evidence: mutable branch/tag names, local edits, ignored generated files, stale submodules or wrong remotes make the build differ from the assumed source

Step 6 Special cases and limits Narrow the fault

A clean working tree does not show it is on the intended commit or synchronized with a remote. git pull combines operations whose merge/rebase behavior depends on configuration. A pushed commit does not show deployment. Removing a file in a new commit does not erase it from history. Keep local refs/objects, index/working tree, remote state and deployed/runtime artifact as separate evidence layers.

Step 7 Common mistakes Narrow the fault
  • Committing secrets.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Commit small, meaningful changes. git status and git diff before committing. Never commit secrets — if you did, rotate them. Use branches and pull requests for review.

Key checks
  • git status / git log --oneline -5 — repository state
  • ldd <binary> — shared libraries
  • ldconfig -p | grep <lib> — libraries in the linker cache
  • make --version; gcc --version — build tools
ReferenceImportant terms & boundaries6 sections · depth on demand

What this shows and what it does not

A branch or tag name is not immutable build identity; the exact commit and effective working tree used by the build must be pinned.

In depth

Git on servers: configuration, history and recovery

Git's behaviour is controlled by configuration at several levels. The git-config documentation defines them:

  • system (/etc/gitconfig), global (~/.gitconfig or $XDG_CONFIG_HOME/git/config), local (.git/config in the repository) and worktree.
  • Files are read in that order, and the last value found wins. Environment variables override files, and -c on the command line overrides everything.
  • --show-origin and --show-scope show where a value comes from.

The Pro Git book adds the core workflow: modify in the working tree, stage what belongs in the next commit, and commit the snapshot.

Commands used most

TaskCommand
Status and diffgit status, git diff, git diff --staged
Stage and commitgit add -p, git commit -m "message"
Historygit log --oneline --graph -20, git log -p -- path
Who changed a linegit blame path
Update from the remotegit pull --ff-only
Branch and switchgit switch -c feature, git switch main
Undo local changes to a filegit restore path
Undo a commit safely (new commit)git revert <sha>
Find a lost commitgit reflog
Tag a releasegit tag -a v1.4.2 -m "release"

Server-specific settings

SettingPurpose
user.name, user.emailIdentify commits (per person, never a shared account)
pull.ff onlyNever create accidental merge commits on servers
safe.directoryAllow repositories owned by another user (set only in system or global scope)
core.sshCommandA specific deploy key for one repository

Recovering from mistakes

git reflog lists every position HEAD has been at, including commits that are no longer on any branch. After an accidental reset --hard, the lost commit can almost always be found there and restored.

host$ git config --show-origin --show-scope --get-all user.email
global  file:/home/alice/.gitconfig     alice@example.net
host$ git config --global pull.ff only
host$ git -C /srv/infra pull
fatal: detected dubious ownership in repository at '/srv/infra'
host$ git config --global --add safe.directory /srv/infra
host$ git -C /srv/infra reset --hard HEAD~2
host$ git -C /srv/infra reflog -3
2d77c1a HEAD@{0}: reset: moving to HEAD~2
4b1e2f0 HEAD@{1}: commit: nginx: raise client_max_body_size for uploads
host$ git -C /srv/infra reset --hard 4b1e2f0

Reading the example

"dubious ownership" means the repository belongs to another user than the one running Git. That's a protection against malicious hooks and configuration in shared directories. Adding the path to safe.directory is the supported way to allow it. The reflog shows the commit position before the accidental reset, so it can be restored.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

Git is part of Software & Source → Git. Git in the Linux Software & Source branch covers using a repository as the local source input for a build: repository identity, checked-out commit, dirty state, submodules and reproducible handoff into the build process.

Git tracks repository objects/refs and working-tree/index state; compilers/linkers transform source through build inputs into binaries; dynamic loaders resolve shared libraries at runtime.

Topic-specific state model. Git in the Linux Software & Source branch covers using a repository as the local source input for a build: repository identity, checked-out commit, dirty state, submodules and reproducible handoff into the build process.

Interpretation rule. - Repository directory ≠ expected repository.

  • Branch/tag name ≠ immutable commit identity.
  • Clean main tree ≠ submodules/generated inputs correct.
  • Git success ≠ downstream build or workload success.

Specialized mechanics

Git stores content as objects referenced by commits, trees and blobs; refs such as branches/tags point to commits while HEAD identifies the checked-out reference or detached commit. The index is a staging state separate from both HEAD and the working tree. Remotes and remote-tracking refs are local metadata about external repositories, not live views. Understanding these four states—object/ref, index, working tree and remote—is essential before destructive reset/clean operations.

Quick reference

Git essentials for admins (configs, scripts, IaC):

git clone git@git.example.com:ops/configs.git
git status; git diff; git log --oneline --graph -20
git switch -c fix/nginx-timeouts
git add -p; git commit -m 'nginx: raise proxy_read_timeout for reports'
git push -u origin fix/nginx-timeouts
git restore file; git reset --soft HEAD~1
git blame nginx.conf

Track /etc changes with etckeeper (commits automatically on package operations). Never commit secrets — scan with gitleaks/trufflehog and use .gitignore; rotate anything that was committed even briefly.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. A branch or tag name is not immutable build identity; the exact commit and effective working tree used by the build must be pinned.

A clean Git working tree does not show the intended commit was deployed.

ReferenceConfiguration & state2 sections · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. This Linux Git Topic owns source-input use on a Linux host; the full Git workflow, merge/rebase/push semantics and CI/CD integration remain in Automation → Git.

Specialized lifecycle

Keep author/identity, remotes, branch upstreams, hooks and credential helpers scoped appropriately. Use .gitignore for untracked-file policy, not to remove already tracked content. Before history rewriting or forced push, establish whether commits are shared and preserve a recovery reference. Pin deployed code to an explicit commit/tag rather than an ambiguous branch name when reproducibility matters. Do not store secrets in history; removing them requires history rewrite plus credential rotation, not just deleting the working-tree file.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Software & Source → Git. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://git-scm.com/docs · confidence 94%
2026-09-13 · vendor docGit current

Authoritative Linux project/vendor documentation reviewed for bounded reference claims: repository object/ref/index/working-tree state and branch/deployment identity. Documentation-based technical verification only; not lab or production-runtime proof. The schema vendor_doc method is used for authoritative project/vendor documentation; deployment applicability remains separate evidence.

Basis: https://git-scm.com/docs · confidence 93%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
git source linuxgit checkout build sourcelinux git repository
Embedded reference data

Quick lookup tables

Git operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Git.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateGit in the Linux Software & Source branch covers using a repository as the local source input for a build: repository identity, checked-out commit, dirty state, submodules and reproducible handoff into the build process.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin exact source/revision or recovery point → verify inputs/consistency → observe copy/build/link result → read back destination/artifact and metadata/dependencies → restore/run in intended environment → repeat original workload + regression check.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainrepository/remote identity → fetch/object availability → ref resolution → HEAD commit → working tree/index/submodules → build input snapshot → artifactTrace requested/configured state through effective state to the observed workload result.
Failure boundaryA branch or tag name is not immutable build identity; the exact commit and effective working tree used by the build must be pinned.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux backup/source evidence can establish this proof path: repository/remote identity → fetch/object availability → ref resolution → HEAD commit → working tree/index/submodules → build input snapshot → artifactUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove unobserved data, metadata, revisions, dependencies, consumers or time periods. A branch or tag name is not immutable build identity; the exact commit and effective working tree used by the build must be pinned.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven backup/source/build boundary, capture adjacent identity/read-back/runtime evidence, make only the demonstrated persistent change, then repeat the original workload plus a regression check.Continue to the next unresolved boundary while preserving the original test condition.

Git · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryGit
Topic pathSoftware & Source → Git
Runtime stateGit in the Linux Software & Source branch covers using a repository as the local source input for a build: repository identity, checked-out commit, dirty state, submodules and reproducible handoff into the build process.
Fast checks- Record repository origin and exact commit hash used for the build. - Inspect working tree/index plus submodule state and generated/untracked inputs that can affect output. - Pass the immutable source identity into build/release metadata where possible. - Verify the resulting artifact and workload rather than treating checkout success as completion.
Verification chainrepository/remote identity → fetch/object availability → ref resolution → HEAD commit → working tree/index/submodules → build input snapshot → artifact Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary.
Failure boundaryA branch or tag name is not immutable build identity; the exact commit and effective working tree used by the build must be pinned. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.

Git · specialized operational reference

Topic-specific Linux mechanics, lifecycle, proof path and failure-boundary lookup.

Operational boundaryTopic-specific reference
StatesHEAD/ref · index · working tree · remote-tracking refs
Syncfetch updates remote-tracking; compare commits explicitly
SafetyPreserve refs before destructive history changes
ProofIntended commit maps to built/deployed running artifact
Confirmation

Confirm action

Continue?