File Status Lifecycle in Git

File has four states in Status lifecycle. that are

  1. Untracked state : Files are present in the local directory, but not added in the github repository index.
  2. Unmodified state : Files are already present in directory or added using $git add command. If some changes did, then it not get tracked. Also after commiting the changes file status become unmodified.
  3. Modified state : When previously tracked file is edited, but not commit the changes.
  4. Staged state : When files committed and ready to push in git repository, then they have staged status.

File has two states tracked and untracked. Previous snapshot are maintained in tacked file.

Lets see example to unserstand above concepts:

$ git init
$ git clone
$ git clone examples

git init creates Git repository skeleton(.git) which contains all neccesary repository files in the currently working directory.
git clone used to copy existing project locate in repository. From above example, project get copied into python-learning directory, Whereas in second case existing project will get copy into examples directory.

$ vi
$ git status

unstage is previously tracked file, but changes in file does not commited and hence it showing output as Changes not staged for commit. So to track the files we need to add file. There are three way to add file:
$git add filename ==>used to add particular file
$git add . ==>use to add all untracked file and modified file
$git add /path/to/filename ==>use to add file at particular location

We'll use,

"$ git add * " and then "$ git status"

Then output will be,


Now files are modified and need to change status into staged.Commit a snapshot of all changes in the working directory. This only includes modifications to tracked files Three way to commit changes:
1. $git commit -a -m " your message"
2. git commit -m " your Message"
3. gitcommit -v -m "Message"

Lets see one by one,

$ git commit -a -m "First Commit" commit1

$ git commit -m "Second Commit" commit2

$ git commit -v -m "Third Commit" commit3

Commit performed, Now time to push files from staging area to git repository by following commands

$ git push

To push changes from staging area to git repository

$ git push -u origin master

Branch master set up to track remote branch master from origin.

$ git pull origin master

To make directory locally available

Thanks.! Please share and comment.