I’d like to start this blog with a few real-world examples on how to set up SubGit assuming infrastructure that is already in place. This post will take place in a strange world of Windows.
Initial configuration: VisualSVN Server on 64-bit Windows computer, provides read and write access to two Subversion repositories over HTTPS.
Primary Objective: Make Subversion repositories accessible for reading and modification with Git over HTTPS.
Secondary Objective: Reuse existing authentication settings, that are already configured for Subversion repositories.
In other words I’m about to set up instant bidirectional Svn to Git replication.
Configuration Details
This is a VisualSVN configuration I’ve created for this guide:
As you may see project repository is a single-project one with a standard trunk/branches/tags layout, and main repository contains two subproject, each with a standard layout.
VisualSVN is installed in C:\Program Files (x86)\VisualSVN Server directory.
Repositories are located in C:\Repositories directory.
VisualSVN uses standard Subversion authentication settings.
Add Git to Svn
First, install msysGit, you may download installer from their download page. Make sure you select this option when installing msysGit (it is important for enabling HTTP access later!):
Second, change an account VisualSVN service uses and modify C:\Repository directory (one where repositories are kept) permissions as described in a Visual SVN knowledge base entry. It is important to make VisualSVN service run on behalf of the account that has access to the Git you’ve just installed. Following the way of lesser resistance, I’ve used my personal account for that, but you may create a dedicated one.
After completing this step, I had VisualSVN service running on behalf of “HOST\alex” account and C:\Repository was writable for “HOST\alex”. Yes, my name is Alex.
Finally, download SubGit zip archive and unpack it into C:\SubGit directory. The run “subgit install” on Subversion repositories to enable replication:
> C:\SubGit\bin\subgit install C:\Repositories\main > C:\SubGit\bin\subgit install C:\Repositories\project
Note, that you must run “subgit install” on behalf of the same user that you’ve configured VisualSVN service with.
Configure HTTP Access for Git
Important: VisualSVN comes with more or less truncated version of Apache, but fortunately it misses only one module of those needed for Git (mod_cgi). Download it (mod_cgi.so from Apache 2.2.21 for win32) and put into C:\Program Files (x86)\VisualSVN Server\bin directory.
Alternatively, you may get this missing module by installing Apache and taking mod_cgi.so file from the modules folder.
Then, edit C:\Program Files (x86)\VisualSVN Server\conf\httpd-custom.conf file:
LoadModule cgi_module bin/mod_cgi.so LoadModule authz_user_module bin/mod_authz_user.so SetEnvIf Request_URI "^/git/.*$" GIT_PROJECT_ROOT=C:/Repositories SetEnvIf Request_URI "^/git/.*$" GIT_HTTP_EXPORT_ALL ScriptAlias /git/ "C:/Program Files (x86)/Git/libexec/git-core/git-http-backend.exe/" <Location /git> Options +ExecCGI Require valid-user AuthName "VisualSVN Server" AuthType Basic AuthBasicProvider file AuthUserFile "C:/Repositories/htpasswd" </Location>
Note, that this configuration example uses “Basic” authentication option, granting read and write access to repositories for all Git users that are listed in htpasswd file. Of course you may configure something more complicated here.
Now restart VisualSVN Server service. That’s all!
Git for Svn
Try the following commands now:
# set this environment variable in case you're using SSL and # self-signed SSL certificate in VisualSVN (this is default). > SET GIT_SSL_NO_VERIFY=true > git clone https://alex@localhost/git/project project > git clone https://alex@localhost/git/main/git/library lib
Thanks to SubGit, changes pushed from the cloned Git repository will be immediately propagated to the corresponding Svn repository and vice versa – new Svn revisions will be received by a pull performed from a cloned Git repository.
You may find more on SubGit at http://subgit.com/



Thanks for the information.
It seems there is a change in behavior.
I need to use
subgit install I:/Repositories/jose
instead of
subgit install I:\Repositories\jose
Results from subgit install
/e/subgit/bin subgit install I:\Repositories\jose
SubGit version 1.0.0-EAP (‘Miai’) build #1096
This is an EAP build, which you may not like to use in production environment.
Detecting paths eligible for translation…
Subversion to Git mapping has been configured in ‘I:\Repositoriesjose’:
: I:\Repositoriesjose\.git
Translating Subversion revisions to Git commits…
Subversion revisions translated: 0.
Total time: 3 seconds.
INSTALLATION SUCCESSFUL
Subversion repository path: ‘I:\Repositoriesjose’.
You may now run
git clone “I:/Repositoriesjose” “Repositoriesjose-git”
to obtain Git clone of Subversion repository.
/e/subgit/bin subgit install I:/Repositories/jose
SubGit version 1.0.0-EAP (‘Miai’) build #1096
This is an EAP build, which you may not like to use in production environment.
Detecting paths eligible for translation…
Subversion to Git mapping has been configured in ‘I:\Repositories\jose’:
: I:\Repositories\jose\.git
Translating Subversion revisions to Git commits…
Hello,
There should be no difference using I:/Repositories/jose or I:\Repositories\jose on Windows.
I’m afraid the formatting of you comment is somehow broken, so it’s not clear what’s wrong with the output. If you actually hit any problem, please add an issue at our tracker —
http://issues.tmatesoft.com/issues/SGT
Thanks!
Hi,
When trying a git push I get the following error any ideas:
Counting objects: 4, done.
Delta compression using up to 24 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 296 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: bash.exe: warning: could not find /tmp, please create!
remote: java.lang.NoClassDefFoundError: org/tmatesoft/translator/SubGitHook
remote: Caused by: java.lang.ClassNotFoundException: org.tmatesoft.translator.Suremote:
remote: at java.net.URLClassLoader$1.run(Unknown Source)
remote: at java.security.AccessController.doPrivileged(Native Method)
remote: at java.net.URLClassLoader.findClass(Unknown Source)
remote: at java.lang.ClassLoader.loadClass(Unknown Source)
remote: at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
remote: at java.lang.ClassLoader.loadClass(Unknown Source)
remote: Could not find the main class: org.tmatesoft.translator.SubGitHook. Proremote: l exit.
remote: Exception in thread “main” [chlewis@swsrvapps-01 ~/chris_test]$
Thank you for reporting this issue. I’ve created an issue for it (http://issues.tmatesoft.com/issue/SGT-433).
It looks like Git pre-receive hook is started, but it fails to locate SubGitHook on the classpath. It would be great if you could take a look at repository/.git/hooks/pre-receive script to see if classpath is correct there. Thanks!
Hi,
I have checked the file and the following is given (note no cygwin installed) how would i check, I can’t see where the SCRIPT_DIR variable is set :
JAVA_HOME=”/C/Program Files (x86)/Java/jre6″
JAVA_EXE=”$JAVA_HOME/bin/java.exe”
MAIN_CLASS=org.tmatesoft.translator.SubGitHook
TS_CLASSPATH=”$SCRIPT_DIR/../../subgit/lib/subgit-1.0.0-EAP_902.jar”:”$SCRIPT_DIR/../../subgit/lib/svngitkit-2.0.0-SNAPSHOT_r2748_v20111207_2017.jar”:”$SCRIPT_DIR/../../subgit/lib/svnkit-1.7.0-SNAPSHOT_r8358_v20111220_1803.jar”:”$SCRIPT_DIR/../../subgit/lib/commons-codec-1.4.jar”:”$SCRIPT_DIR/../../subgit/lib/sequence-library-1.0.0.jar”:”$SCRIPT_DIR/../../subgit/lib/sqljet-1.1.0-SNAPSHOT_r1158_v20110809_2108.jar”:”$SCRIPT_DIR/../../subgit/lib/antlr-runtime-3.1.3.jar”:”$SCRIPT_DIR/../../subgit/lib/jna-3.2.7.jar”:”$SCRIPT_DIR/../../subgit/lib/annotations-7.0.3.jar”:”$SCRIPT_DIR/../../subgit/lib/org.eclipse.jgit-0.11.3-sgk-SNAPSHOT_t20111003_2148.jar”:”$SCRIPT_DIR/../../subgit/lib/jsch-0.1.44-1.jar”:”$SCRIPT_DIR/../../subgit/lib/jansi-1.6.jar”
when I use svn to commit
Z:\test\trunk\1.txt
Z:\test\trunk\1.txt
Commit failed (details follow):
Commit blocked by pre-commit hook (exit code 1) with output:
access deined
and when I use git push
git push
Password for ‘http://dd@192.168.12.3′:
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 287 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://dd@192.168.12.3/git/test
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ‘http://dd@192.168.12.3/git/test’
Hello,
Thank you for your feedback!
The reason might be that you have installed SubGit on behalf of Administrator user (or on behalf of some other user), and repository files owner thus has been changed.
At the same time VisualSVN’s Apache may be ran as a service with ‘Network Service’ privileges and may have no access to repository files or permissions to run newly created hooks.
I would recommend you to change VisualSVN Apache service settings so that it is ran as Administrator, then restart the service.
Thanks,Ok now
and how to use git >>>checkout svn branch ?
First, clone Git repository
> git clone http://dd@192.168.12.3/git/test test
Then, in your Git repository clone, just run:
> cd test
> git checkout branchName
This will work assuming your Subversion repository has the following structure:
/trunk
/branches
/tags
and your branch is located at /branches/branchName and has been translated during initial translation phase (when you were installing SubGit).
thanks
git push
Password for ‘http://dd@192.168.12.3′:
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 254 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: bash.exe: warning: could not find /tmp, please create!
remote: bash.exe: warning: could not find /tmp, please create!
To http://dd@192.168.12.3/git/test
7500d27..ec009f2 master -> master
======================
remote: bash.exe: warning: could not find /tmp, please create!
I can ignore the message?
or I must add tmp path config in [hooks] and [daemon] ?
You may ignore this message, it is a warning only.
To get rid of it you need Apache pass TMP environment variable to the Git hooks. To do that, please follow instructions at this comment:
http://issues.tmatesoft.com/issue/SGT-429#comment=60-3712
i.e. Add mod_env.so to VisualSVN server and add ‘PassEnv TMP’ to http-custom.conf
subgit register –key c:\subgit.key svn_repo
SubGit version 1.0.0-RC1 (‘Miai’) build #1519
Registration information:
Registered for: dd
Purchase ID: dd
Committers Limit: 3
You may use this key to register 2 more repositories (out of 3).
==============
then
git clone svn_repo
and I change git commit username & email ,modify code,git push over 3 times
git config user.name user1
git config user.email user1@xx.com
..modify
git commit -m xxxx
git push
==============
git config user.name user2
git config user.email user2@xx.com
..modify
git commit -m xxxx
git push
…………………………..
etc…….
and No warning or error , says Committers Limit: 3?
in my clean vmware xp 32 bit
git push , to subgit installed repo ,very fast
but in my win7 64 bit,
git push ,
Password for ‘https://dd@localhost’:
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 251 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
show immediately
===================
and wait about 70 seconds show
remote: bash.exe: warning: could not find /tmp, please create!
wait another 40 seconds to the second
remote: bash.exe: warning: could not find /tmp, please create!
To https://dd@localhost/git/dd
fd612f8..ff87fed master -> master
==========
and I create pure git repo
then ,git push , no delay, pushed immediately
Could you please send us the logs from SVN_REPOS/subgit/logs directory? Please open an issue at http://issues.tmatesoft.com/issues/SGT and attach logs to it.
That performance issue might be related to the lack of TMP directory, could you please fix this TMP issue and try pushing again? To fix issues with the temp directory do the following:
Add mod_env.so to VisualSVN server and add ‘PassEnv TMP’ to http-custom.conf (see also http://issues.tmatesoft.com/issue/SGT-429#comment=60-3712).
I fixed tmp issue
same problem
SGT-493