Last Updated: February 25, 2016
·
1.568K
· zzet

Save tags and branches with git filter-branch

If you want run git filter-branch and save refs, you must add --tag-name-filter 'cat' to your command.

For example:

I replace in repository (from file .gitmodules) git://some.host/+some/group/repo.git with git://some.host/group/repo.git and want to save tags.

My command like this:

git filter-branch --tag-name-filter 'cat' --tree-filter '
    if [ -f .gitmodules ];
      then
        cat .gitmodules | sed -e "s/\+[a-zA-Z]*\///g" >> .tmpgitmodules && mv .tmpgitmodules .gitmodules;
      else
        echo "";
      fi' -- --all

After run I save all refs. They was updated from old to new sha.