0 votes
in Git by

What is the difference between HEAD, working tree and index, in Git?

1 Answer

0 votes
by
A single git repository can track any number of branches, but your working tree is always referring just one of them (the "current" or "checked out" branch), and HEAD points to that branch.

HEAD is the commit at the top of the current branch. If you've just checked out the branch, i.e. have no modified files, then its content matches the working tree. As soon as you modify anything, it no longer matches.

A working tree is the dir and sub-directory within it that contain the source files. It can be anywhere, but normally it is the same dir in which the hidden .git dir is located.

The index/staging area 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.

Related questions

0 votes
asked Sep 3, 2020 in Git by SakshiSharma
0 votes
asked Feb 13, 2022 in Git by rajeshsharma
...