linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Chapters
  • How it works
  • Lessons
  • Knowledge base
  • Interview prep
home/git/kb/Git basics/working-tree

kb/basics ── Git basics ── beginner

Working tree

The files and directories of your project on disk: the ones you open in your editor. One of Git's three zones, alongside the index ([[add]]) and the repository ([[commit]]).

view as markdownaka: work-tree, workdir

The working tree (also "working copy") is simply the project files as you see and edit them. Git is not directly tied to them: it sits alongside them in .git/ and watches.

What "tracked" means

Every file in the working tree is in one of four states from Git's point of view:

  1. Untracked. The file exists on disk, but Git knows nothing about it. It has never been in the index or a commit.
  2. Tracked, unmodified. The file is in the repository (in the latest commit) and is identical on disk to that commit.
  3. Tracked, modified. The file is in the repository, but the version on disk differs from what is in HEAD.
  4. Tracked, staged. The file's changes have been added to the index via git add and are ready to commit.

A file can be both staged and modified at the same time: you staged one change, then made another. In that case git status shows the file in both sections simultaneously.

A clean working tree

A "clean" working tree means no modified, no staged, and no untracked files. git status prints:

nothing to commit, working tree clean

This state matters. Many commands (for example, git pull or git switch) may refuse to run when the working tree is "dirty" and the operation would overwrite your changes.

To bring the working tree to a clean state quickly:

  • commit the changes (git add + git commit),
  • stash them (git stash),
  • discard them (git restore <file> or git reset --hard).

.gitignore and the working tree

Files listed in .gitignore physically exist in the working tree, but Git does not show them as untracked and does not offer to add them. This is useful for build artifacts, local config files, and IDE metadata.

To check why a specific file is being ignored:

bash
git check-ignore -v <file>
# .gitignore:5:node_modules/    node_modules/main.js

Pitfalls

  • The working tree is not the same thing as a checkout. A checkout is an operation (replace the working tree's state with the contents of another commit). The working tree is the state itself.
  • Bare repositories (git init --bare) have no working tree at all: only the contents of .git/. They are used for the server side of git push/fetch.
  • When you switch branches, Git rewrites the working tree with the contents of the target commit. Unsaved changes can block that. Running git stash before switching solves the problem.

§ команды

bash
git status

Shows the state of all three zones, including the working tree

bash
git diff

Difference between the working tree and the index (what is not yet staged)

bash
git restore <file>

Revert a file in the working tree to the state in the index

bash
git clean -fd

Delete untracked files and empty directories (use with care)

§ см. также

  • addgit addMoves file changes from the working tree into the index (staging area). Does not commit anything. It only controls what goes into the next commit.
  • commitCommitA Git object: a snapshot of the entire project (via a tree) plus metadata including author, committer, date, parents, and message. The SHA of a commit includes the parent's SHA, which makes history cryptographically linked.
  • statusgit statusShows the difference between three Git zones: what is modified in the working tree, what is staged in the index, and which branch is active. The safest command in Git: it changes nothing and you can run it as often as you like.
  • vcsVersion control systemA tool that stores the history of file changes, lets you return to past versions, and lets multiple people collaborate on the same project. Three generations: local, centralized, distributed.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies