Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete branch with all commits pushed to wrong repository?

We have several git repositories working on Android projects. We have 'boot' repo which is small and 'android' which is huge. During development one of our guys pushed branch from 'android' to 'boot' and now boot repository size is 700 MB! Is there anyway to completely delete the wrong branch and all commits related to it from 'boot' now?

I tried filter-branch and other methods, but most of them change commit numbers made after that wrong push

In theory this shouldn't be a problem delete commits which are 'on the side'. This branch was never merged to 'master' and these commit are not parents to any useful commits

like image 850
mishmashru Avatar asked Mar 01 '11 12:03

mishmashru


2 Answers

Deleting a branch from a remote server is done using git push

git push --delete boot branchname

After this each person can run the following command on their local repo to remove the deleted branch.

git remote prune boot

After the branch is removed though, the data will still linger in each repository for 2-4 weeks by default as a measure to prevent accidental data loss. If the disk space concern is really that important to you, then it can be removed sooner but take note that this will remove all unreachable objects that are being kept temporarily to prevent accidental data loss.

git gc --aggressive --prune=now
like image 158
Arrowmaster Avatar answered Oct 08 '22 23:10

Arrowmaster


Deleting the branch is done by

git branch -D branch_name

Note the capital -D option: this tells git to delete the branch even if it's not fully merged into master.

After doing that, fire up the garbage collector with git gc. Then, you should be fine.

like image 30
eckes Avatar answered Oct 09 '22 01:10

eckes