Skip to content

Instantly share code, notes, and snippets.

@jamesmyatt
Created July 3, 2014 12:56
Show Gist options
  • Save jamesmyatt/4bbde4fed7a878836960 to your computer and use it in GitHub Desktop.
Save jamesmyatt/4bbde4fed7a878836960 to your computer and use it in GitHub Desktop.
Script to remove obsolete SVN branches from git-svn repository
svn_repos=`git config --get-all svn-remote.svn.url`
svn_prefix=svn/
git branch -r | sed 's|^[[:space:]]*||' | grep "^${svn_prefix}" | grep -v "^${svn_prefix}tags/" > git-branch-list
svn ls $svn_repos/branches | sed 's|^[[:space:]]*||' | sed 's|/$||' | sed "s|^|${svn_prefix}|" > svn-branch-list
echo "${svn_prefix}trunk" >> svn-branch-list
diff -u git-branch-list svn-branch-list | grep '^-' | grep -v '^--' | sed 's|^-||' > old-branch-list
echo 'Obsolete branches:'
cat old-branch-list
read -n1 -r -p "Press any key to continue..." key;
for i in `cat old-branch-list`; do git branch -d -r "$i"; rm -rf .git/svn/refs/remotes/"$i"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment