Git basics: status and add commands
By GitHub
Key Concepts
- Git Status: A command to view the state of the working directory and staging area.
- Working Directory: The files currently present on your local machine.
- Staging Area (Index): An intermediate area where changes are prepared for commit.
- Git Add: A command to add files from the working directory to the staging area.
- Untracked Files: Files in the working directory that Git is not currently monitoring.
- Tracked Files: Files that Git is monitoring for changes.
- Commit: A snapshot of the changes in the staging area.
Checking Repository Status & Untracked Files
The initial state of a new Git repository, as revealed by the git status command, indicates “nothing to commit.” This signifies that no files have yet been added for tracking. The git status command is the primary tool for understanding the current state of the repository – specifically, what files have been modified, added, or deleted.
Creating and Identifying Untracked Files
A new file, hello.md, is created using the touch hello.md command. Running git status again now reveals hello.md as an “unchecked file.” This designation means the file exists in the working directory but is not yet being monitored by Git. Untracked files are not included in any commits until explicitly added.
Adding Files to the Staging Area
The git add command is used to move files from the working directory into the staging area. Two primary methods are demonstrated:
git add .: This command adds all files in the current working directory to the staging area. It’s a convenient way to stage all changes at once.git add <filename>: This command adds a specific file to the staging area. For example,git add learning.pyadds only thelearning.pyfile.
Further files, learning.py and waiting.py, are created to illustrate selective staging. Running git add learning.py stages only learning.py. A subsequent git status confirms this: learning.py is now listed as being in the staging area, while waiting.py remains an untracked file in the working directory.
The Staging Area as Safekeeping
The staging area is described as a “safekeeping” location for changes. The git add command effectively tells Git to “keep track of this file in its current state.” This is crucial because Git doesn’t automatically track every change made to tracked files.
Tracking Subsequent Changes
The transcript emphasizes that if further modifications are made to files already being tracked, the git add command must be executed again to register those newer changes. Git only stages the version of the file that was last added. Therefore, continuous use of git add is necessary to accurately reflect the evolving state of the project.
Chat with this Video
AI-PoweredHi! I can answer questions about this video "Git basics: status and add commands". What would you like to know?