If changes are limited to commits to existing branches and creating labels, you can save a backup copy of the refs directory inside the repository (usually the .git directory). something like:
$ tar -cf /путь/к/архиву .git/refs
it contains all the pointers (and the commits to which they point) - both branches ( branches ) and tags ( tags ).
if the changes you make affect something more global (renaming / creating / deleting branches or remote repositories, changes in the repository configuration, etc.), you should also save the config file:
$ tar -cf /путь/к/архиву .git/refs .git/config
to “roll back”, it is enough to delete this directory and restore it from a backup. something like:
$ rm -r .git/refs; tar -xf /путь/к/архиву
and a working copy can be brought to the desired state, as usual, with the checkout command:
$ git checkout коммит-или-ветка-или-метка
If desired, the local storage can be “cleaned” by the gc command from the accumulated “garbage”:
$ git gc
git clone /home/test/myrep). And togit push --tagsaccordingly there (justgit push --tags). With the right approach, local cloning is very fast (just copy files). And then you can delete the cloned folder. - KoVadim