7

how can I Clear repository and push new one instead of it .

I have project with size more than 2GB , I checked .git folder and it's size is 1.5GB , I try to delete .git folder after that I did git init and force push project , but remote repository size not changed , my steps :

git init
git add . 
git commit -m "First Push"
git remote add origin http://Url_here
git push -f origin master

how to replace repository content ?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Wael Abo-Aishah
  • 942
  • 2
  • 10
  • 27

3 Answers3

12

log in as root remove .git

sudo rm -R .git

Log in as correct user

git init
git remote add origin https://[name]@bitbucket.org/frankdesign/[new-repo].git
git add .
git commit -m "new clean repo"
git push --force origin master
Devang Padhiyar
  • 3,427
  • 2
  • 22
  • 42
3

Few options:

  • Go to the server repository, delete the old repo and create a new one.
    In the current repo push the new branches

  • Create a new orphan branch and then push it.
    Now on your server run git gc --aggressive --prune=now to clean all the old commits

  • Use filter branch to clean all the old content

  • Use rebase -i and squash all your commits into one then push it

  • Use git subtree' split to create a new project from the existing code.Similar togit filter-tree` which in your with the right code will produce the same results.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Can I change content by force push to the same repository ? I did it befor and done , but now cannot clean the repository ! – Wael Abo-Aishah Mar 15 '16 at 19:51
  • You can and then execute a git GC to clean old unrefered content – CodeWizard Mar 15 '16 at 19:53
  • after force push to the repository run (git GC) ? I will try it – Wael Abo-Aishah Mar 15 '16 at 19:55
  • Yep. `git gc --aggressive --prune=now` will clean all the content which is not in any commit. but if you have branches you will have to push each branch (force push) – CodeWizard Mar 15 '16 at 19:56
  • I apply it , but Repository size not decreazed ! Does that decrease Repo size ? – Wael Abo-Aishah Mar 15 '16 at 20:03
  • Why wont you simply delete the old repo by deleting the .git folder on the remote server and then do a `git init --bare`. now push your branches to it and check the size. – CodeWizard Mar 15 '16 at 20:04
  • Here you can read about more advanced options how to fix your branches. http://stackoverflow.com/questions/34519665/how-to-move-head-checkout-revert-reflog-reset-old-commit/34519716#34519716 – CodeWizard Mar 15 '16 at 20:14
0

See Force "git push" to overwrite remote files

I think you are adding the origin master to your push force, so you are not overwriting everything...

git push -f

But this is replacing everything in the repository....

Community
  • 1
  • 1
eesdil
  • 1,931
  • 3
  • 16
  • 25