Level 2
Name | Link | Status |
---|---|---|
Level 2 | https://github.com/aruncs31s/git_by_doing_level_2 | Done |
Task: Understanding git add
and git status
Task | Run CMD | Learn What? | git cmd |
---|---|---|---|
Task 1 | python task_1.py |
git add |
add |
Task 2 | python task_2.py |
git status |
status |
Task 3 | python task_3.py |
git restore |
restore |
First Run task_1.py
Python task_1. Py
It will tell you to add some file , so you can type 'n' to exit program or press "CTRL and c" at the same time and interrept it.
The run the task_1. Py again , and answer the question.
Then Run task_2.py
Python task_2. Py
Then Run task_3.py
Python task_2. Py
After finishing the Task 3, run the quiz. Py
Python quiz. Py
git add
Git add is used to add
that file to staging area. I assume no bulb is lit. So
- What is staging ?
Imagine some coder (me) coding a simple quiz like this. How did that get there? He must have uploaded it. But since we are working withgit
, how do we do that with thegit
?. Good question , we usegit add
to add the files.
Add to where?
Remember the original Question "What is Staging ?" , when you add something using git add
git goes to staging area. This is a advance topic and you can skip this from here

You can see some new terms in the above picture like
- Untracked Files
- Commit
- Unmodified
- Modified
- Staged
In simple terms a file has 4 states
- Modified: means the contents of the file have been changed
- Unmodified: you know what it is.
- Untracked: Which means
git
has nothing to do with this file - Staged:
git
do have bussiness with this file
git status
is used to check the status of a file
We will now consider these 2 stages Untracked and Staged
-
touch
is used to create an empty file
 -
this is before i created
add_me
 -
this is after i created
add_me

You can see in the Untracked file
we now have add_me
and it says right there (use "git add <file>....)
so what if we do ?
So i run
git add add_me

Now there is a new section and it says
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: add_me
is says .... to unstage
so the file add_me is staged
.
In summary , staging means preparing a file for upload. (we will use the term upload now , but it is called something else (push).)
When do you use the git add
- To add new files to staging area
- When you modify an exisiting file and upload the modified file.
You can add multiple files or just add all files using -A
option
Git add -A
git restore
As i've said earlier , when you use git add
the file get stages , so when i file staged the git
start do things to that file , and one of them is to keep a copy of that file and if you accidently delete a staged file , you can recover it using the following command
git restore <file name>