Git and GitHub for Beginners #4

Abhishek Raghav
3 min readJun 20, 2020
Source: Google

Tracking our Project

In my previous blog, I discussed about three stage architecture of git. Now continuing to that, let us start tracking our project.

  • Setting our username and email:

First of all, let us set our username and email with the git. Username is necessary because it lets the git know which user has committed what changes. So execute the following commands now one by one.

git config --global user.name "<your_user_name>"git config --global user.email "<your_email>"

Now your username has been set in git. You can check it by the executing the following command:

git config user.name

It will print your username in the output.

  • Adding files to staging area:

First of all let me create a project with say three files: “hello world.py”, “fibonacci.py” and “factorial.py” and initialize the repository.

Now when I check the status of my repository:

git status

I get the following output:

On branch masterNo commits yetUntracked files:
(use "git add <file>..." to include in what will be committed)
factorial.py
fibonacci.py
hello world.py
nothing added to commit but untracked files present (use "git add" to track)

It shows that currently all files are untracked. Suppose we want to add factorial.py to the staging area. Then we execute the command:

git add factorial.py

Now if we again check the status of repository, it shows:

On branch masterNo commits yetChanges to be committed:
(use "git rm --cached <file>..." to unstage)
new file: factorial.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
fibonacci.py
hello world.py

You can also add multiple files at a time to repository by writing their names separated by spaces as:

git add <file_name_1> <file_name_2> <file_name_3>

Otherwise, to add all the untracked files at a time, we can execute the command:

git add -A

Thus, now if we check the status of our repository, it will be something like this:

On branch masterNo commits yetChanges to be committed:
(use "git rm --cached <file>..." to unstage)
new file: factorial.py
new file: fibonacci.py
new file: hello world.py
  • Committing the changes:

For committing our changes to repository, just execute the command:

git commit -m "<your_message>"

Using the flag “-m” allows you to write a message along with your changes so that you can know in future what changes you had made in which commit. In my case, I am giving the message “initial commit”. So I execute the command:

git commit -m "initial commit"

It shows me a message like this:

[master (root-commit) 5cdc9df] initial commit
3 files changed, 25 insertions(+)
create mode 100644 factorial.py
create mode 100644 fibonacci.py
create mode 100644 hello world.py

Now if we check the status of our repository, it will show this:

On branch master
nothing to commit, working tree clean

Now we can do the above process repeatedly, whenever we make some changes in our code and wish to commit.

  • Checking the commit history of repository:

We can check the commit history of our repository by running the following command:

git log

It gives us the commit history as follows:

commit fec2a05066ae897622e376efd6f43524b9c00890 (HEAD -> master)
Author: user_name <email@email.com>
Date: Sat Jun 20 17:42:12 2020 +0530
wrote fibonacci function using dynamic programming
commit 5cdc9df4ee9ce96d093c3fdbd6cd1f976bf4a409
Author: user_name <email@email.com>
Date: Sat Jun 20 17:24:01 2020 +0530
initial commit

You see that every commit in git is associated to a unique hash string code which is generated using SHA-1 algorithm.

Thus, in this article you learnt how to track your git repository. Hope you enjoyed reading this article.

Thanks for reading :)

Do comment in your views and feedback below.

--

--

Abhishek Raghav

Hey there! I am an undergrad at IIT Jodhpur (2019–23) pursuing B. Tech. in CSE. Being a tech enthusiast, I love to gain and share knowledge about tech content.