GIT : Basic Concepts & Terms

2022-03-13

Basic Concepts & Terms in GIT can be easily understood easily with below GUIs

GIT Add & GIT Commit



GIT Data Transport Commands




3 Trees in GIT




GIT File Status Life Cycle


When you first create a file in a git folder the file is assigned and untracked status. 

This means that git is not actively watching this file, it will be ignored if any changes are occur to it. 

For git to start watching this file we have to issue a command that will move it to Tracked status. The command is called git add. Let’s say that now we start working on that file and we do some changes to it. Once we save the file it will mark with a modified status. 

At this point we’re confident the work is ready to go out, either will push it to a production environment or we want all the developers to check our work. And, we finally issue the git commit command. It will take all the files back to the tracked status, ready to begin the whole process again.,

If you consider a file in your Working Directory, it can be in three possible states.

1.  It can be staged. Which means the files with the updated changes are marked to be committed to the local repository but not yet committed.

2.  It can be modified. Which means the files with the updated changes are not yet stored in the local repository.

3.  It can be committed. Which means that the changes you made to your file are safely stored in the local repository.

HEAD in GIT



The above fig shows the HEAD referencing commit-1 because of a 'checkout' was done at commit-1. When you make a new commit, it shifts to the newer commit. The git head command is used to view the status of Head with different arguments. It stores the status of Head in .git\refs\heads directory.

 The git show head is used to check the status of the Head. This command will show the location of the Head. In the below output, you can see that the commit id for the Head is given. It means the Head is on the given commit.

GIT Index

  The git “index” is where you place files you want committed to the git repository. Before you “commit” (checkin) files to the git repository, you need to first place the files in the git “index”. The Index Isn’t The Working Directory. The working directory is where you do your work: You add, remove, and modify files in the working directory. Files in the git index are files that git would commit to the git repository if you used the git commit command.

   The index is also known as cache, directory cache, current directory cache, staging area, staged files.

   The index is not the working directory: you can type a command such as git status, and git will tell you what files in your working directory have been added to the git index (for example, by using the git add filename command).

   The index is a single, large, binary file in <baseOfRepo>/.git/index, which lists all files in the current branch, their sha1 checksums, time stamps and the file name -- it is not another directory with a copy of files in it.

   The index is a staging area where the new commit is prepared. Essentially, the contents of the index are what will go into the new commit (though if you do git commit -a, this will automatically add all changes to files that Git knows about to the index before committing, so it will commit the current contents of your working tree). git add will add or update files from the working tree into your index.

How to see what files are in the Git Index

$ git ls-files

Master

In Git, "master" is a naming convention for a branch. After cloning (downloading) a project from a remote server, the resulting local repository has a single local branch: the so-called "master" branch. This means that "master" can be seen as a repository's "default" branch.

The Working Directory

This is where your files reside and where you can try changes out before committing them to your staging area (index) and then into repository.

    Only four commands that prompt network interactions in Git

            There are only four commands that prompt network interactions in Git. A local repository has no awareness of changes made on the remote repository until there is a request for information. And, a remote repository has no awareness of local changes until commits are pushed.

The four network commands are:
1. git clone
2. git fetch
3. git pull
4. git push

0 comments: