gitgithubinitialization

How to compact the '.git' directory in Git


Here is the respective size of directories inside of a Ruby on Rails application 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 folder .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.


Solution

  • 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