Tutorial 2 : Tracking the changes using Git

Gaurav Patil
2 min readJul 17, 2022

--

Photo by Gabriel Heinzer on Unsplash

Missed previous tutorial ? — click here.

We will cover following topics in this tutorial :

Tracking the changes

Adding the changes

Committing the changes

Tracking the changes :

Let’s make changes in sample.html file created in previous tutorial and save that file in same trial folder. We are just changing the font size of the heading by replacing h1 tag with h3 tag as I have done below:

<html>
<body>
<h3>This is a heading.</h3></body>
</html>

Let’s check the working directory’s status in command prompt :

git status

Output :

On branch master
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: sample.html
no changes added to commit (use “git add” and/or “git commit -a”)

It says :

  1. We have modified sample.html (in Red color) file but those changes are not accommodated in the repository, change is only being made in the working directory.
  2. To replicate same changes in the our repository, we need to add this modified file and commit it.
  3. To undo the changes use “git restore sample.html” (Try this command and check git status.)

Adding the changes :

Run following commands in command prompt:

git add sample.html
git status

Output :

On branch master
Changes to be committed:
(use “git reset <file>” to unstage)
modified: sample.html

It says :

  1. The modified sample.html (in Green color) file is in the staging area meaning that the change is not permanent in the repository. The next commit will include the changes staged.
  2. We can use the “git reset sample.html” command to unstage these changes. (Try this command and check git status.)

Committing the changes :

Run following command in command prompt :

git commit -m “added h3 tag”

In above command, you can write any message followed by “-m”.

Output :

[master fb91519] added h3 tag
1 file changed, 1 insertion(+), 1 deletion(-)

Now check git status in command prompt :

git status

Output :

On branch master
nothing to commit, working tree clean

This means changes we made in the sample.html file are now accommodated in our repository.

Congratulations !!! You are no more novice in using git.

Now this is pretty clear why git is called version control system i.e. how it tracks the changes made in the project files.

Whatever changes we made, were in master(main) branch. But what is branch in Git ? Take a deep breath and move to the next tutorial to learn everything about branch in Git.

--

--

Gaurav Patil
Gaurav Patil

Written by Gaurav Patil

Machine Learning Engineer drawing insights from mathematics.

No responses yet