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/Everyday workflow/add

kb/workflow ── Everyday workflow ── beginner

git add

Moves file changes from the working tree into the index (staging area). Does not commit anything. It only controls what goes into the next commit.

view as markdownaka: git-add, stage

git add is the most frequent Git command after git status. It handles the transition from "edits on disk" to "edits ready to commit".

What happens under the hood

For each file:

  1. Reads the content from the working tree.
  2. Creates a blob object in .git/objects/.
  3. Updates the record in .git/index: path, permissions, blob SHA.

After this, git status shows the file under "Changes to be committed".

Basic forms

bash
git add file.txt          # single file
git add src/              # directory, recursively
git add .                 # everything from the current directory
git add -A                # all changes across the entire repository
git add '*.py'            # by glob pattern

The difference between . and -A: the dot adds only from the current working directory; -A looks at the whole repository regardless of where you are.

Interactive mode

bash
git add -p file.txt

Splits the edit into hunks (chunks with ±3 lines of context) and asks about each one: y to add, n to skip, s to split into smaller pieces, e to edit manually. This is the primary tool for splitting one file that has two unrelated changes into two separate commits.

Pitfalls

  • git add file.txt writes the current contents to the index. If you edit the file again after add, the old version stays in the index. git status will show the file under both "to be committed" and "not staged". Run git add again to catch up.
  • New files are not tracked by default. They appear as untracked until you add them explicitly. There is no automatic registration. This is intentional: accidental files (logs, build artifacts) should not end up in the index.

§ команды

bash
git add file.txt

Add a single file to the index

bash
git add -A

Add all changes across the repository: new, modified, deleted

bash
git add -p

Interactive hunk-by-hunk staging

bash
git add -u

Only modified tracked files (excludes new untracked files)

§ см. также

  • 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.
  • commit-cmdgit commitCaptures what is in the index as a new commit object and moves the current branch to that commit. Without arguments it opens an editor for the message; the most common form uses `-m`.
  • blobBlobA Git object that stores the content of a single file. Just bytes, no name, no permissions, no date. The filename lives in the `tree`, not in the blob.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies