There isn't an API for that because the "project size" isn't the size of the files tracked in the main or master branch, but rather the total size of the project including tracked files, the ENTIRE git history (everything in the .git
directory), etc. So for example, if you were to download 5k images from FontAwesome and commit them to your git repo then remove them later, your projects size would still reflect them since they’re in the git history. You can see this reflected on the Project Overview page for your project. Under the project name you'll see things like the number of commits, branches, tags, and then two attributes called Files and Storage. The Files value is the raw file size of the individual files tracked by git for your main/master branch. Storage is the total size of the project including git history, commit messages, etc.
To get the size of the files in any branch, you can:
#1: check out that branch
git checkout my_feature_branch
# get the file size
du -sh $(pwd)
The du
command (for disk usage) shows you the disk usage of the given file or directory and each subdirectory, in bytes. The -s
flag tells du
to only show the total disk usage for the (s)pecified directory. The -h
flag tells du
to give the result in a (h)uman readable format (KB, MB, GB, TB, etc. instead of bytes).