git - workflow with remote svn repositories
I’m going to try a new git-svn workflow. Previously I did a git svn clone and also created a backup on my backup server as a remote. So pictorially something like this:
local-git-svn-clone
/ \
/ \
/ \
remote-svn backup-server
This worked OK but I’ve made mistakes in the local-git-svn-clone and have had to start all over because things got out of sync. Most often this would happen if I merged into the master branch pushed to the backup-server than then did a “git svn rebase”. I would end up not being able to do any more pushes to the backup-server.
To try to reduce the possibility of mistakes I’m going to try separate repos. So I first. cloned the svn repo as normal:
<local>$ git svn clone -s svn+ssh://wink@<remote-svn-rep>/<path to repo> <local-git-svn-clone>
Then I made a local clone of local-git-svn-clone:
<local>$ git clone local-git-svn-clone local-clone
Next ssh into my backup-server and create a bare shared repo.
<local>$ ssh wink@<backup-server> <backup-server>$ cd <git-repos> <backup-server>$ mkdir <backup-repo> <backup-server>$ cd <backup-repo> <backup-server>$ git --bare init --shared <backup-server>$ exit <local>$
Now back on my local machine I push the local-git-svn-clone repo to the backup repository.
<local>$ cd <local-clone> <local>$ git remote add backup git://<backup-server>/<backup-repo> <local>$ git push --repo=backup --all
So at this point <local-clone> points at <local-git-svn-clone> and <backup-repo> which I don’t want. What I want is <local-clone> to just point at <backup-repo>. There may be a simpler way to do this, but I choose to actually delete <local-clone> and create it anew from <backup-repo>.
<local>$ cd .. <local>$ rm <local-clone> <local>$ git clone git://<backup-server>/<backup-repo> <local-clone>
So now I have two separate repos on local. <local-clone> connected to <backup-server>/<backup-repo> and <local-git-svn-clone> connected to the <remote-svn-repo>/<path to repo>.
local-clone << git pull >> local-git-svn-clone
/ \
/ \
/ \
back-repo backup-server
Without the direct connection between , but since they are both based on the svn repo I can easily pull local-clone from local-git-svn-clone.
With this configuration you work on branches in local-clone, don’t work on master, the goal is to keep local-clone master exactly the same as local-git-svn-clone. If you don’t do this it will you’ll see trapezoidal commits and things get confusing.
So the work flow becomes:
local-clone$ git checkout -b x local-clone$ hack local-clone$ git commit (or git gui) local-clone$ test local-clone$ repeat more hack/commit/test local-clone$ git push --all
So you’ve been working a while and periodically pushing to your back-repo to backup local-clone. Eventually you’ll want to commit the work you’ve done. To do this you’ll pull the changes from local-clone x branch to local-git-svn-clone, svn rebase, test and svn dcommit.
local-git-svn-clone$ git pull <local-clone> x:master local-git-svn-clone$ git svn rebase local-git-svn-clone$ test local-git-svn-clone$ git svn dcommit
If the git svn rebase pulled in a lot of changes you may want to pull these over to local-clone if there and hack/test/commit then back to the above. Eventually you’ll do the svn dcommit.
The last step is to get the changes in local-git-svn-clone into local-clone and push them to backup-repo.
local-clone$ git pull <local-git-svn-clone> local-clone$ git branch -D x local-clone$ git push
Of course you don’t need to delete the branch x but all of those changes are now in the local-clone master so they aren’t needed.