Branches and References

Learn how branches are managed by Git.

References to commits

Git manages branches by using references pointing to the commits. This mechanism allows instant branch creation without cloning the whole project folder.

HEAD file

The HEAD file stores the current commit hash. Run the following commands in the terminal below:

$ ls -a
$ cd .git
$ cat HEAD

The command cat HEAD prints ref: refs/heads/New because we have an initial branch master, and then we create and check out to a branch New. It shows New since we’re currently at New. If we switch to master using the checkout command, it shows ref: refs/heads/master.

Get hands-on with 1400+ tech skills courses.