After a lot of searching, I finally found an answer...
git clone git@myhost:mybackup.git newdirectory
cd newdirectory
git fetch origin refs/remotes/*:refs/remotes/*
git init
Now a git branch -a
shows all of my remote branches.
I'm not sure if the git init
is needed here or if it is only needed in the git init --bare
variant (see the commented out lines in the shell script below), but I am sure that it harms nothing to leave it in if it is not needed.
My main reason in doing this is to get my SVN tags/branches copied over rather than only having master
pointing to SVN trunk
and without having to parse the entire SVN history (very slow for projects with a lot of history, tags and branches). So to copy over my SVN info:
git svn init -s "svn://mysvnhost/mysvnrepo/myproject"
git svn fetch
git checkout master
To speed this process up, I created a shell script:
#!/bin/sh
#
# git-clone-svn-based-repo.sh:
#
# clones a git-svn based repo including all SVN commits without pounding
# the SVN server for hours (just a quick refresh taking seconds)
#
usage_exit ()
{
echo "Usage: $0 <git-repo> <dest-directory> <svn-project>"
exit 1
}
if ! git ls-remote "$1" > /dev/null 2>&1
then
echo "No git repo found at: $1"
usage_exit
fi
if [ -r "$2" ]
then
echo "File or directory already exists: $2"
usage_exit
fi
if ! svn ls "$3" 2> /dev/null | grep -q trunk
then
echo "No SVN project found at: $3"
usage_exit
fi
# create new bare git repo
mkdir "$2"
cd "$2"
git init --bare .git
# fetch everything from backup
git remote add backup "$1"
git fetch backup refs/remotes/*:refs/remotes/*
git fetch backup refs/heads/*:refs/heads/*
git fetch backup refs/tags/*:refs/tags/*
# disable future fetching from backup
# setup to push all remote refs to backup by default
git config remote.backup.fetch do_not_fetch_from_backup
git config remote.backup.push '+refs/remotes/*:refs/remotes/*'
# initialize git repo to usable (non-bare) state
git init
# update SVN references
git svn init -s "svn://svn.crc-corp.com/carsrepository/$3"
git config svn.authorsfile $HOME/projects/authors.txt
git svn fetch
# update master to current SVN trunk
git checkout master
git svn rebase
# update ignore properties from SVN
git svn show-ignore >> .git/info/exclude
In order to create such a backup from an existing git SVN repo:
# create a bare backup repo at git@myhost:mybackup.git
git remote add backup git@myhost:mybackup.git
git config remote.backup.fetch do_not_fetch_from_backup
git config remote.backup.push '+refs/remotes/*:refs/remotes/*'
git push backup