0
0
Gitdevops~5 mins

Working directory state in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you work on files in a project, the working directory is where you make changes. It shows the current state of your files before you save or share them with others.
When you want to see which files you have changed but not yet saved to the project history.
When you want to check if you have new files that are not yet tracked by the project.
When you want to prepare files to be saved in the project history by adding them to the staging area.
When you want to undo changes in your files before saving them.
When you want to confirm the exact changes you made before sharing your work.
Commands
This command shows the current state of your working directory and staging area. It tells you which files are changed, new, or ready to be saved.
Terminal
git status
Expected OutputExpected
On branch main Your branch is up to date with 'origin/main'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: example.txt Untracked files: (use "git add <file>..." to include in what will be committed) newfile.txt no changes added to commit (use "git add" and/or "git commit -a")
This command shows the exact changes you made in the files that are not yet saved. It helps you review your edits line by line.
Terminal
git diff
Expected OutputExpected
diff --git a/example.txt b/example.txt index e69de29..d95f3ad 100644 --- a/example.txt +++ b/example.txt @@ -0,0 +1,2 @@ +Hello world +This is a new line
This command moves your changed file into the staging area, preparing it to be saved in the project history.
Terminal
git add example.txt
Expected OutputExpected
No output (command runs silently)
Run again to see that example.txt is now staged and ready to be saved.
Terminal
git status
Expected OutputExpected
On branch main Your branch is up to date with 'origin/main'. Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: example.txt Untracked files: (use "git add <file>..." to include in what will be committed) newfile.txt
Key Concept

If you remember nothing else from this pattern, remember: the working directory shows your current file changes before you save them to the project history.

Common Mistakes
Trying to save changes without adding files to the staging area first.
Git only saves files that are staged, so unstaged changes will not be included in the save.
Use 'git add <file>' to stage your changes before committing.
Ignoring untracked files and expecting them to be saved automatically.
New files are not tracked until you add them, so they won't be saved or shared.
Use 'git add <newfile>' to start tracking new files.
Not checking 'git status' before committing.
You might miss files that are not staged or accidentally commit incomplete changes.
Always run 'git status' to review your working directory state before saving.
Summary
Use 'git status' to see which files are changed, new, or staged.
Use 'git diff' to review exact changes in your files before saving.
Use 'git add' to stage files so they will be saved in the next commit.