git add
The command that copies a file's current content into the staging area so it will be part of the next commit.
In more detail
git add reads the file as it is at that moment, stores the content as a blob and records its ID in the index. Editing the file afterwards changes only the working tree; run git add again to stage the newer content. It is also how you start tracking a new file.
Example
git add notes.txtRelated terms
- staging area — Git's list of exactly what the next commit will contain, kept in the file .git/index; also called the index.
- git add --patch — A way of staging only some of the changes in a file, by answering yes or no to each hunk Git shows you.
- tracked file — A file Git already knows about because it is in the last commit or the staging area; any other file is untracked.
- git commit — The command that records the staging area as a new commit whose parent is the current commit, then moves the current branch to it.
Taught in
- A Repository Is A Folder With A Memory — Advanced Git Internals & Distributed Workflows
- The Three Areas: Working Tree, Index, Repository — Advanced Git Internals & Distributed Workflows
- Staging Deliberately: status, add, add --patch — Advanced Git Internals & Distributed Workflows
- Ignoring Files, And The Tracked File Trap — Advanced Git Internals & Distributed Workflows
- Undoing: restore, reset, revert And stash — Advanced Git Internals & Distributed Workflows
- What A Remote Actually Is — Advanced Git Internals & Distributed Workflows
- Resolving A Conflict, Line By Line — Advanced Git Internals & Distributed Workflows