How to Remove Git repository and push new one

11,138

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 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.

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
Share:
11,138
Wael Abo-Aishah
Author by

Wael Abo-Aishah

Updated on June 04, 2022

Comments

  • Wael Abo-Aishah
    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 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
    CodeWizard about 8 years
    It will not work. the content will still be in the repo. it will not be cleaned !!!
  • Wael Abo-Aishah
    Wael Abo-Aishah about 8 years
    Can I change content by force push to the same repository ? I did it befor and done , but now cannot clean the repository !
  • CodeWizard
    CodeWizard about 8 years
    You can and then execute a git GC to clean old unrefered content
  • eesdil
    eesdil about 8 years
    yep you are right, forgot that the git was inited, so lost the connections to the repo...
  • Wael Abo-Aishah
    Wael Abo-Aishah about 8 years
    after force push to the repository run (git GC) ? I will try it
  • CodeWizard
    CodeWizard about 8 years
    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)
  • Wael Abo-Aishah
    Wael Abo-Aishah about 8 years
    I apply it , but Repository size not decreazed ! Does that decrease Repo size ?
  • CodeWizard
    CodeWizard about 8 years
    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
    CodeWizard about 8 years
    Here you can read about more advanced options how to fix your branches. stackoverflow.com/questions/34519665/…
  • Tom N Tech
    Tom N Tech over 4 years
    Apparently this doesn't work. The old commits are still on the server.