Recording Changes
Recording Changes
States of a file
At this point, you should have a real Git repository on your local machine, and all of its files in front of you. Typically, you’ll want to start making changes and committing snapshots of those changes into your repository each time the project reaches a state you want to record.
Remember that each file in your working directory can be in one of two states:
Untracked state
Untracked files are not the files which git is simply not interested in
Tracked state
Tracked files are files that Git knows about
Tracked files are files that were in the last snapshot, as well as any newly staged files
Files which are in tracked state can be in any one of the condition below
Unmodified condition
Modified condition
Staged condition

Check the status
Let us check the status of our working directory with the below command
git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
hello.txt
nothing added to commit but untracked files present (use "git add" to track)
We can see that the file is in untracked state
Adding or tracking new files
In order to begin tracking a new file, you use the command git add
. To begin tracking the hello.txt
file, you can run this:
git add hello.txt
If you run your status command again, you can see that your file is now tracked and staged to be committed:
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: hello.txt
Note: The git add
command takes a path name for either a file or a directory; if it’s a directory, the command adds all the files in that directory recursively.
Committing changes
Let us commit the changes to our local repository using the below command
git commit -m "initial content"
[master (root-commit) b1e291c] initial content
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
Now you’ve created your first commit! You can see that the commit has given you some output about itself:
which branch you committed to (
master
),what checksum the commit has (
b1e291c
),how many files were changed, and
statistics about lines added and removed in the commit.
Note: we will discuss branch later, checksum is a unique identifier issued by git database.
Let us check the status again
Let us check the status again to confirm if our commit went through by using the same command we used earlier:
git status
On branch master
nothing to commit, working tree clean
The message we get from Git is self-explanatory.
Last updated