Skip to content

Instantly share code, notes, and snippets.

@jcanfield
Created October 11, 2014 21:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcanfield/0ef633f21515a69bf513 to your computer and use it in GitHub Desktop.
Save jcanfield/0ef633f21515a69bf513 to your computer and use it in GitHub Desktop.
Optimize and Shrink your GIT Repository (Ruby Script). From Jeff Smith @ rallydev.com.
#!/usr/bin/env ruby
# Original Scripting by Jeff Smith at http://rallydev.com/, https://www.rallydev.com/community/engineering/shrinking-git-repository-move-githubcom.
module ShrinkIt
BUCKETS = 4
def self.remove(files)
files.each_slice(files.size / BUCKETS) do |portion|
paths = portion.join(" ")
ShrinkIt.stream_command("git filter-branch --index-filter 'git rm --cached --ignore-unmatch #{paths}'")
ShrinkIt.stream_command("rm -rf .git/refs/original/")
ShrinkIt.stream_command("git reflog expire --expire=now --all")
ShrinkIt.stream_command("git fsck --full --unreachable")
ShrinkIt.stream_command("git repack -A -d")
ShrinkIt.stream_command("git gc --aggressive --prune=now")
end
end
def self.stream_command(cmd)
puts "#{Time.new} Starting #{cmd}"
IO.popen(cmd) do |data|
while line = data.gets
puts line
end
end
end
end
large_files = []
large_files << "largefile1.jar"
large_files << "HugeDirectory/*"
large_files << "ThirdParty/*"
large_files << "Stuff/*"
large_files << "sub-project/*"
large_files << "zipNotNeededAnymore.zip"
ShrinkIt.remove(large_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment