Last active
September 6, 2019 11:33
-
-
Save ajaysuwalka/5a95892a927258ef1169f4e784d10c3a to your computer and use it in GitHub Desktop.
Remove branches and Releases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://help.github.com/en/articles/splitting-a-subfolder-out-into-a-new-repository | |
https://help.github.com/en/articles/duplicating-a-repository | |
$ git clone --bare https://github.com/exampleuser/old-repository.git | |
Create a new repository | |
$ cd old-repository.git | |
$ git push --mirror https://github.com/trilogy-group/aurea-aes-edi-test-automation.git | |
# Very important - Now clone the repo again so that you don't mess with existing repo. | |
## Ref - https://ben.lobaugh.net/blog/201616/cleanup-and-remove-all-merged-local-and-remote-git-branches | |
# Make the branch as default whichever you think is correct and has all the artifacts mostly develop, in rare case master | |
for remote in `git branch -r `; do git branch --track $remote; done | |
git checkout develop | |
git tag | xargs -L 1 | xargs git push origin --delete | |
git branch --merged master | grep -v master | cut -d/ -f2- | xargs -n 1 git push --delete origin | |
## Ref - https://stackoverflow.com/questions/19542301/delete-all-tags-from-a-git-repository/34395864#34395864 | |
It may be more efficient to push delete all the tags in one command. Especially if you have several hundred. | |
In a suitable non-windows shell, delete all remote tags: | |
git tag | xargs -L 1 | xargs git push origin --delete | |
Then delete all local tags: | |
git tag | xargs -L 1 | xargs git tag --delete | |
This should be OK as long as you don't have a ' in your tag names. For that, the following commands should be OK. | |
git tag | xargs -I{} echo '"{}"' | tr \\n \\0 | xargs --null git push origin --delete | |
git tag | xargs -I{} echo '"{}"' | tr \\n \\0 | xargs --null git tag --delete | |
To fetch the latest references - | |
git fetch --prune | |
To put it simple, if you are trying to do something like git fetch -p -t, it will not work starting with git version 1.9.4. | |
However, there is a simple workaround that still works in latest versions: | |
$ git tag -l | xargs git tag -d # remove all local tags | |
$ git fetch -t # fetch remote tags | |
A one liner can be written as: | |
$ git tag -l | xargs git tag -d && git fetch -t | |
https://silentinfotech.com/blog/remove-deleted-files-from-git-repository-history/ | |
Shrink the repository | |
We used git-filter-branch to get rid of files from commits. People expect the resulting repository to be smaller than the original, but you need a few more steps to actually make it smaller because Git tries hard not to lose your objects until you tell it to. | |
Remove the original refs backed up by git-filter-branch (do this for all branches): | |
git update-ref -d refs/original/refs/heads/master | |
Expire all reflogs with: | |
git reflog expire --expire=now --all | |
Garbage collect all unreferenced objects with | |
git gc --prune=now | |
You are ready to push now. | |
git push | |
Push your updated tree on the git repository. Make sure you have enough rights to do so. | |
git push -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment