Back

Explore Courses Blog Tutorials Interview Questions
+2 votes
2 views
in DevOps and Agile by (19.4k points)
edited by

Can someone tell me the difference between HEAD, working tree and index, in Git?

From what I understand, they are all names for different branches. Is my assumption correct?

Edit

I found this

A single git repository can track an arbitrary number of branches, but your working tree is associated with just one of them (the "current" or "checked out" branch), and HEAD points to that branch.

Does this mean that HEAD and working tree are always the same?

1 Answer

+2 votes
by (27.5k points)

Working trees: They are nothing but the files that you are currently working on.

HEAD: HEAD is a pointer to the branch or commit that you last checked out, and which will be the parent of a new commit if you make it. For example, if you're on the master branch, then HEAD will be pointing to master, and when you commit, that new commit will be a descendant of the revision that your master pointed to, and master will be updated to point to the new commit.

Index: The git "index" is where you place files you want commit to the git repository.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). The command git add will add or update files from the working tree into your index.    

Browse Categories

...