How to Remove Git repository and push new one
Solution 1
Few options:
Go to the server repository, delete the old repo and create a new one.
In the current repo push the new branchesCreate a new
orphan
branch and then push it.
Now on your server rungit gc --aggressive --prune=now
to clean all the old commitsUse
filter branch
to clean all the old contentUse
rebase -i
and squash all your commits into one then push itUse
git subtree' split to create a new project from the existing code.Similar to
git filter-tree` which in your with the right code will produce the same results.
Solution 2
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
Wael Abo-Aishah
Updated on June 04, 2022Comments
-
Wael Abo-Aishah almost 2 years
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 didgit 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 about 8 yearsIt will not work. the content will still be in the repo. it will not be cleaned !!!
-
Wael Abo-Aishah about 8 yearsCan I change content by force push to the same repository ? I did it befor and done , but now cannot clean the repository !
-
CodeWizard about 8 yearsYou can and then execute a git GC to clean old unrefered content
-
eesdil about 8 yearsyep you are right, forgot that the git was inited, so lost the connections to the repo...
-
Wael Abo-Aishah about 8 yearsafter force push to the repository run (git GC) ? I will try it
-
CodeWizard about 8 yearsYep.
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) -
Wael Abo-Aishah about 8 yearsI apply it , but Repository size not decreazed ! Does that decrease Repo size ?
-
CodeWizard about 8 yearsWhy 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 about 8 yearsHere you can read about more advanced options how to fix your branches. stackoverflow.com/questions/34519665/…
-
Tom N Tech over 4 yearsApparently this doesn't work. The old commits are still on the server.