Skip to content

Cloning of Local Repository (git-svn)

Context

In some cases it takes days time to convert a large Subversion to a local Git repository using git svn clone <svn-url>. So the plan is to use that Git repository as a Git remote and intermediate to Subversion.

The reason it takes so long is that the Subversion repository needs to be cloned from the start to be successful in many cases.

At the Git-SVN Repository

This side is in this story is called 'remote'. The branch needed is hotfix.

Show at the Subversion cloned Git repository all the branches located in the subdirectory git-svn-repo.

git -C git-svn-repo branch -a
Results...
* master               
  remotes/origin/hotfix
  remotes/origin/tags/v0.0.0
  remotes/origin/tags/v0.0.1
  remotes/origin/trunk

The Git config shows the connection between branches and Subversion

git -C git-svn-repo config --local --list
svn-remote.svn.url=https://<svn-host-domain>/svn/myrepo
svn-remote.svn.fetch=trunk:refs/remotes/origin/trunk
svn-remote.svn.branches=branches/*:refs/remotes/origin/*
svn-remote.svn.tags=tags/*:refs/remotes/origin/tags/*

Checkout the needed branch hotfix here as well to allow a push when used as a remote.

git -C git-svn-repo checkout -b hotfix origin/hotfix
Result shows hotfix branch is created.
* hotfix
  master
  remotes/origin/hotfix
  remotes/origin/tags/v0.0.0
  remotes/origin/tags/v0.0.1
  remotes/origin/trunk

Creating the Remote Repository

This side is in this story is called 'local'.

Creating empty local Git repository called myrepo.

mkdir -p myrepo
# Initialize empty repository.
git -C myrepo init
# Add remote called origin. 
git -C myrepo remote add origin "<directory-to-git-svn-repo>/.git"

Show all branches on remote origin.

git -C myrepo ls-remote origin
Reports...
0a2f27dfa1cb959aa5f94a2cc8ebdac93a173583        HEAD
0a2f27dfa1cb959aa5f94a2cc8ebdac93a173583        refs/heads/hotfix
96554c3a59c2414e780ce17e55c8cebad07151ae        refs/heads/master
0a2f27dfa1cb959aa5f94a2cc8ebdac93a173583        refs/remotes/origin/hotfix
e254a7ddd7b97f1ffa3ec8b244821bb4128be299        refs/remotes/origin/tags/v0.0.0
81374d15071c6d858f744ca8694c94206351c52f        refs/remotes/origin/tags/v0.0.1
96554c3a59c2414e780ce17e55c8cebad07151ae        refs/remotes/origin/trunk

Remote refs/heads/hotfix is available because of the checkout at the 'remote' earlier.

Fetch a branch hotfix which is here named local-hotfix as a local branch.

git -C myrepo fetch origin hotfix:local-hotfix

Check if the branch exists.

git -C myrepo branch -vv
````
Reports...
```text
local-hotfix a173583 Added line in hotfix.

The tracking remote branch is not visible yet.
To make that happen the next command is needed.

git -C myrepo branch --set-upstream-to=origin/hotfix local-hotfix
Show local branch connected to the newly assigned remote upstream branch.
git -C myrepo branch -vv 
Reports...
* local-hotfix 952f227 [origin/hotfix] Added line in hotfix.

Show how things are configured for remote named origin.

git remote show origin

Show the tracking upstream per branch.

git -C myrepo for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads

Operation

At multiple local Git repositories commits can be made and pushes can be performed on the remote. On the remote the command git diff origin/hotfix the differences ar shown between the current Subversion side.

Some commands in logical order that could apply...

git switch hotfix
git diff origin/hotfix
git svn fetch
git diff origin/hotfix
git svn rebase
git svn dcommit