In GitHub URL's: what is the difference between a tree and a blob? In GitHub URL's: what is the difference between a tree and a blob? git git

In GitHub URL's: what is the difference between a tree and a blob?


GitHub's website currently seems to be:

  • Using blob for files, and tree for directories, in URLs;
  • Redirecting browsers which request file URLs containing tree to contain blob instead; and
  • Redirecting browsers which request directory URLs containing blob to URLs containing tree instead.

It's possible that GitHub's website, at the time you asked the question, was only rewriting file URLs between tree and blob, instead of properly redirecting them. (Rewriting and redirecting URLs are activities of web servers.) If so, then the change wouldn't appear in your browser's address bar. But maybe you didn't mean that.


I found this article helpful. This explains the git objects in detail.

Essentially, a blob is just a bunch of bytes that could be anything, like a text file, image, actual source code etc.

A tree is like a directory, it points to:

  • blob objects (how a directory points to other files)
  • other trees (how a directory can have subdirectories)
       tree  /     |    \blob   tree  blob        |       blob

Hopefully the above example clarifies the difference.

In your example, Podfile is a file containing source code. Hence, it is a blob object. However, git is smart and realizes this fact. Hence, when you click the link, it changes the tree in the link to blob. You can try and test this yourself by clicking the below tree link:

https://github.com/facebook/pop/tree/master/Podfile

Similary, if you go to a directory on a git repository it is a tree object. Again, if you change the tree to blob git is smart and realizes that it is actually a directory and not a file and changes the blob in the link to tree. Again, you can try and test this yourself:

https://github.com/facebook/pop/blob/master/pop-tests

In terms of which link to prefer when you want to add to a documentation, it depends on what does the link point to, essentially there are 4 types of git objects:

  • blob - file
  • tree - directory
  • commit - reference to tree
  • tag - reference to commit

Hope that answers your question. I still recommend going through the article to get a thorough understanding of git objects.


A blob is a representation of a file, and file diffs are separated into contiguous modified chunks named hunks. Hunks are @@ delimited lines in the git diff output format.

A tree is a representation of a directory. There are different types of trees:

  • working tree

    The tree of actual checked out files. The working tree normally contains the contents of the HEAD commit tree, plus any local changes that you have made but not yet committed.

  • index

    A collection of files with stat information, whose contents are stored as objects. The index is a stored version of your working tree. Truth be told, it can also contain a second, and even a third version of a working tree, which are used when merging.

  • tree-ish

    A ref pointing to either a commit object, a tree object, or a tag object pointing to a tag or commit or tree object.

There are four types of objects in Git’s internal storage. Commit objects, annotated tag objects, blobs and tree objects.

References