Life cycle of file in git

explain the life cycle and a brief of git status command

Life cycle of file in git

Hello everyone! So in previous blog I explained about what some basic terms like working directory, staged area and local repository are. Don't worry if you don't remember it right away, we will be talking about it a lot and also as for remote repository, i'll cover that part too. Let's continue with starter's first then we will proceed to main course.

Life cycle of file in Git :

So, in this blog we will be talking about life cycle of a file in git. Every file in git is at one of these states -

  1. untracked files (Git is unaware of these files)

  2. staged files

  3. modified files

  4. In repository / committed


Let's understand each state of a file

  1. untracked files :

    We know that new files are created in working directory, and these new files are untracked by git i.e. git is unaware of this new file. These files are in untracked state, file's in this state are untracked files. They are also termed as unstaged files.

  2. staged files :

    After creating your new files and maybe adding some data in it we proceed to next step which is staging our files.

    When you use git add to stage changes, Git takes a snapshot of the changes you've made to the files in your working directory and puts those changes into the staging area. When the file is in staging area, it's in staged state. These files are also termed as index files.

  3. modified files:

    Any files which is already tracked by git, but is modified in the working directory is said to be in modified state.

    Say you made any new changes to the file which is tracked by git, these files will bein working directory and in modified state.

    If a file is stored and added to staging area/ committed then that file is tracked

  4. committed files:

    So now our files are in staging area, next stage it would be is in local repository, and these files in local repository are in commit state, and we call these files as committed files.

    git commit -m " " command takes a commit msg from user and then along with it, if you have not globally given out your configurations details then takes the configuration details from you.

    git config --global user.name ""

    git config --global user.email ""

    When we enter these details using global, then these configuration details gets applicable for all repository, i.e whenever you make commit in any repository it will consider the configuration details(user name and email id given) by the user is the one who is making these changes.

    When we don't use global, then the configuration is applicable for only that specific repository, i.e. the changes made in the current repository will be under that name and it would not be same for any other repository.

    In real time, when we are working on two different repository, where it's for two separate clients, and we are storing data in two different remote repository, then we might need two different mail configuration, for this sake we need to work without global in real time.


git status command:

git status is a git command which shows the current status of all the files in each area,

The six different states the Git status command can inform you of are:

  1. There is no commit history (When a new repository is created at that time these commits are not made)

  2. There are untracked files (Files in working directory and not known by git)

  3. There are changes to be committed (Files in staging area and in staged state)

  4. The working tree is clean (After a commit i.e the files are in local repo)

  5. Files have been modified (Files in working directory and they are also known by git)

  6. Files have been deleted (Files are not removed)