Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8951237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:37:03+00:00 2026-06-15T13:37:03+00:00

Do you know if there is a way to list the space usage of

  • 0

Do you know if there is a way to list the space usage of a git repository per branch ? (like df or du would)

By “the space usage” for a branch I mean “the space used by the commits which are not yet shared accross other branches of the repository”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:37:04+00:00Added an answer on June 15, 2026 at 1:37 pm

    As it seems that nothing like that already exists, here is a Ruby script I did for that.

    #!/usr/bin/env ruby -w
    require 'set'
    
    display_branches = ARGV
    
    packed_blobs = {}
    
    class PackedBlob
        attr_accessor :sha, :type, :size, :packed_size, :offset, :depth, :base_sha, :is_shared, :branch
        def initialize(sha, type, size, packed_size, offset, depth, base_sha)
            @sha = sha
            @type = type
            @size = size
            @packed_size = packed_size
            @offset = offset
            @depth = depth
            @base_sha = base_sha
            @is_shared = false
            @branch = nil
        end
    end
    
    class Branch
        attr_accessor :name, :blobs, :non_shared_size, :non_shared_packed_size, :shared_size, :shared_packed_size, :non_shared_dependable_size, :non_shared_dependable_packed_size
        def initialize(name)
            @name = name
            @blobs = Set.new
            @non_shared_size = 0
            @non_shared_packed_size = 0
            @shared_size = 0
            @shared_packed_size = 0
            @non_shared_dependable_size = 0
            @non_shared_dependable_packed_size = 0
        end
    end
    
    dependable_blob_shas = Set.new
    
    # Collect every packed blobs information
    for pack_idx in Dir[".git/objects/pack/pack-*.idx"]
        IO.popen("git verify-pack -v #{pack_idx}", 'r') do |pack_list|
            pack_list.each_line do |pack_line|
                pack_line.chomp!
                if not pack_line.include? "delta"
                    sha, type, size, packed_size, offset, depth, base_sha = pack_line.split(/\s+/, 7)
                    size = size.to_i
                    packed_size = packed_size.to_i
                    packed_blobs[sha] = PackedBlob.new(sha, type, size, packed_size, offset, depth, base_sha)
                    dependable_blob_shas.add(base_sha) if base_sha != nil
                else
                    break
                end
            end
        end
    end
    
    branches = {}
    
    # Now check all blobs for every branches in order to determine whether it's shared between branches or not
    IO.popen("git branch --list", 'r') do |branch_list|
        branch_list.each_line do |branch_line|
            # For each branch
            branch_name = branch_line[2..-1].chomp
            branch = Branch.new(branch_name)
            branches[branch_name] = branch
            IO.popen("git rev-list #{branch_name}", 'r') do |rev_list|
                rev_list.each_line do |commit|
                    # Look into each commit in order to collect all the blobs used
                    for object in `git ls-tree -zrl #{commit}`.split("\0")
                        bits, type, sha, size, path = object.split(/\s+/, 5)
                        if type == 'blob'
                            blob = packed_blobs[sha]
                            branch.blobs.add(blob)
                            if not blob.is_shared
                                if blob.branch != nil and blob.branch != branch
                                    # this blob has been used in another branch, let's set it to "shared"
                                    blob.is_shared = true
                                    blob.branch = nil
                                else
                                    blob.branch = branch
                                end
                            end
                        end
                    end
                end
            end
        end
    end
    
    # Now iterate on each branch to compute the space usage for each
    branches.each_value do |branch|
        branch.blobs.each do |blob|
            if blob.is_shared
                branch.shared_size += blob.size
                branch.shared_packed_size += blob.packed_size
            else
                if dependable_blob_shas.include?(blob.sha)
                    branch.non_shared_dependable_size += blob.size
                    branch.non_shared_dependable_packed_size += blob.packed_size
                else
                    branch.non_shared_size += blob.size
                    branch.non_shared_packed_size += blob.packed_size
                end
            end
        end
        # Now print it if wanted
        if display_branches.empty? or display_branches.include?(branch.name)
            puts "branch: %s" % branch.name
            puts "\tnon shared:"
            puts "\t\tpacked: %s" % branch.non_shared_packed_size
            puts "\t\tnon packed: %s" % branch.non_shared_size
            puts "\tnon shared but with dependencies on it:"
            puts "\t\tpacked: %s" % branch.non_shared_dependable_packed_size
            puts "\t\tnon packed: %s" % branch.non_shared_dependable_size
            puts "\tshared:"
            puts "\t\tpacked: %s" % branch.shared_packed_size
            puts "\t\tnon packed: %s" % branch.shared_size, ""
        end
    end
    

    With that one I was able to see that in my 2Mo git repository, I’d got one useless branch which took me 1Mo of blobs not shared with any other branches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know the better way to arrange the list items for
Anyone know if there is a standard way to create a List from an
I know there is a way to extend a JLabel to paint 3D borders
I know there is a way to call Perl routines from C. As shown
I know there's a way, I know I've done it (a long time) before,
Does anyone know is there a way to implement Windows Live ID authentication into
As far as I know there is no way to migrate existing Facebook comments
As far as I know there is no way to do this, but I
I wanted to know if there is way to log the mysql queries in
I wish to know is there any way that I can create the threads

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.