When we run git branch <branchname > , how does GIT know the SHA-1 of the last commit?

GIT uses the reference named HEAD for this purpose. The HEAD file in GIT is a symbolic reference to the current branch we are working on.

A symbolic reference is not a normal reference that contains a SHA-1 value. A symbolic reference contains a pointer to another reference.

When we open head file we see:
$ cat .git/HEAD
ref: refs/heads/master

If we run git checkout branchA, Git updates the file to look like this:

$ cat .git/HEAD
ref: refs/heads/branchA

Read the full book at www.amazon.com
Posted in GIT, GIT Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*