0

Here is the respective size of directories inside of a Rails app that I have inherited:

→ find . -maxdepth 1 -type d -mindepth 1 -exec du -hs {} \;
263M    ./.git
2.0M    ./app
124K    ./config
728K    ./db
4.0K    ./doc
 56K    ./lib
  0B    ./log
232K    ./public
8.0K    ./script
164K    ./spec
560K    ./spreadsheets
 16K    ./test
 64K    ./vendor

I made a new repository off an existing repository branch on Github and left the old one intact. I do not need any history in the new repository since that particular branch of the old repository became the master for the new repository and that is the only branch in the new repository. I would like to get the size of .git to a minimum size to start with since it is an absolute waste in terms of Github space, local space, and Heroku deployment.

Git init did not work. I do not know if I can just

rm -rf .git

and then reinitialize the git repository and then push it to Github remote.

Bharat
  • 2,409
  • 6
  • 32
  • 57
  • If you do not need any history then reset the git by removing the `.git` folder and issuing `git init`. – Gowtham Mar 04 '16 at 05:19

2 Answers2

2

In order to compact .git directory persist just certain branches removing old commits.

Please perform the following steps:

  1. Delete the branches you don't need
  2. Amend commits before the one you need
  3. Perform garbage collection
Community
  • 1
  • 1
Pavel
  • 4,912
  • 7
  • 49
  • 69
0

Execute the following commands:

# remove old content
rm -rf .git

# init new repo
git init

# add all current files (add .gitignore entries if you need to ignore some files)
git add -A .

# commit the current content
git commit - m ".. Message..."

# add the remote url of the github server
git remote add origin <github new url>

# oush your code to github
git push origin master
CodeWizard
  • 128,036
  • 21
  • 144
  • 167