The .git Directory
If you haven’t explored the .git directory yet, it’s worth the hike. Do a cd .git in your local git repository that you’ve cloned from a remote repository and you should find something similar to this:
A brief explanation of the various files and directories:
File/directory | Type | Value | Meaning |
---|---|---|---|
config | text file | [See diagram] | The configuration file for the local git repository |
HEAD | text file | ref: refs/heads/master | Lists a file to read that is the currentHEAD branch: git branch will show the branch that HEAD refers to as the current branch. |
refs | directory | Everything under the refs directory is references to a commit for a branch of some type (either a local branch or a remote tracking branch). | |
refs/heads | directory | Files in the refs/heads directory are branch names. For example a file named refs/heads/master means a branch named master exists in the local repository. The contents of the file is the hash of the most recent commit on that branch. | |
refs/heads/master | text file | 6975b25be537f997c92490c7927cb6886fd5c49f | The most recent commit on this branch (master) |
refs/heads/v1 | text file | fd70e1d85320d12f230d8ff5e6056d86a775a6f3 | The most recent commit on this branch (v1) |
refs/remotes | directory | - | Everything under the refs/remotesdirectory is references to a commit for a remote-tracking branch. |
refs/remotes/origin | directory | - | The remote tracking branches for the remote repository origin are stored in this directory. |
refs/remotes/origin/master | text file | 6975b25be537f997c92490c7927cb6886fd5c49f | The most recent commit on this branch. Note the hash is the same as inrefs/heads/master which means the user has merged the commits from this remote-tracking branch into the user’smaster branch. |
refs/remotes/origin/v0 | text file | e018ab5fe997a56bffb39350543c017684cfd721 | The most recent commit on this branch. Note the hash is the different than the hash in in refs/heads/v1 which means the user’s local v1 branch is behind the commit in the remote-tracking branch’sv1 branch. The user needs to merge the commits from this remote-tracking branch into the user’s v1 branch to catch up to the remote-tracking branch. |