How to Clone SVN Repository Source Code using git via Command Line

Posted on

This is an article concerning on how to clone SVN repository source code using git via command line. Anyone can clone the source code using the URL of SVN repository. The command for cloning the source code must be available in environment. That command for cloning the source code in this article is the ‘git’ command. So, the following are the actual steps for cloning the source code in the SVN Repository :

  1. Check if the ‘git’ command is available in the operating system.

Just type ‘git’ in the command line. If there is a feedback as shown below :

user@hostname:~/repositories/app$ git svn
git-svn - bidirectional operations between a single Subversion tree and git
usage: git svn  [options] [arguments]
Available commands:
  blame            Show what revision and author last modified each line of a file
                     --git-format 
  branch           Create a branch in the SVN repository
                     --commit-url 
                     --destination, -d 
                     --dry-run, -n 
                     --message, -m 
                     --parents 
                     --tag, -t 
                     --username 
  clone            Initialize and fetch revisions
                     --add-author-from 
                     --authors-file, -A 
                     --authors-prog 
                     --branches, --b=s@ 
                     --config-dir 
                     --follow-parent, --follow! 
                     --ignore-paths 
                     --ignore-refs 
                     --include-paths 
                     --localtime 
                     --log-window-size 
                     --minimize-url, --m! 
                     --no-auth-cache 
                     --no-checkout 
                     --no-metadata 
                     --placeholder-filename 
                     --prefix 
                     --preserve-empty-dirs 
                     --quiet, --q+ 
                     --repack-flags, --repack-args, --repack-opts 
                     --repack 
                     --revision, -r 
                     --rewrite-root 
                     --rewrite-uuid 
                     --shared 
                     --stdlayout, -s 
                     --tags, --t=s@ 
                     --template 
                     --trunk, -T 
                     --use-log-author 
                     --use-svm-props 
                     --use-svnsync-props 
                     --username 
  commit-diff      Commit a diff between two trees
                     --copy-similarity, -C 
                     --edit, -e 
                     --file, -F 
                     --find-copies-harder 
                     -l 
                     --message, -m 
                     --revision, -r 
                     --rmdir 
  create-ignore    Create a .gitignore per svn:ignore
                     --revision, -r 
  dcommit          Commit several diffs to merge with upstream
                     --add-author-from 
                     --authors-file, -A 
                     --authors-prog 
                     --commit-url 
                     --config-dir 
                     --copy-similarity, -C 
                     --dry-run, -n 
                     --edit, -e 
                     --fetch-all, --all 
                     --find-copies-harder 
                     --follow-parent, --follow! 
                     --ignore-paths 
                     --ignore-refs 
                     --include-paths 
                     --interactive, -i 
                     -l 
                     --localtime 
                     --log-window-size 
                     --mergeinfo 
                     --merge, -m, -M 
                     --no-auth-cache 
                     --no-checkout 
                     --no-rebase 
                     --quiet, --q+ 
                     --repack-flags, --repack-args, --repack-opts 
                     --repack 
                     --revision, -r 
                     --rmdir 
                     --set-svn-props 
                     --strategy, -s 
                     --use-log-author 
                     --username 
                     --verbose, -v 
  fetch            Download new revisions from SVN
                     --add-author-from 
                     --authors-file, -A 
                     --authors-prog 
                     --config-dir 
                     --fetch-all, --all 
                     --follow-parent, --follow! 
                     --ignore-paths 
                     --ignore-refs 
                     --include-paths 
                     --localtime 
                     --log-window-size 
                     --no-auth-cache 
                     --no-checkout 
                     --parent, -p 
                     --quiet, --q+ 
                     --repack-flags, --repack-args, --repack-opts 
                     --repack 
                     --revision, -r 
                     --use-log-author 
                     --username 
  find-rev         Translate between SVN revision numbers and tree-ish
                     -A, --after 
                     -B, --before 
  gc               Compress unhandled.log files in .git/svn and remove index files in .git/svn
  info             Show info about the latest SVN revision
             on the current branch
                     --url 
  init             Initialize a repo for tracking (requires URL argument)
                     --branches, --b=s@ 
                     --config-dir 
                     --ignore-paths 
                     --ignore-refs 
                     --include-paths 
                     --minimize-url, --m! 
                     --no-auth-cache 
                     --no-metadata 
                     --prefix 
                     --rewrite-root 
                     --rewrite-uuid 
                     --shared 
                     --stdlayout, -s 
                     --tags, --t=s@ 
                     --template 
                     --trunk, -T 
                     --use-svm-props 
                     --use-svnsync-props 
                     --username 
  log              Show commit logs
                     --authors-file, -A 
                     --color 
                     --incremental 
                     --limit 
                     --non-recursive 
                     --oneline 
                     --pager 
                     --revision, -r 
                     --show-commit 
                     --verbose, -v 
  migrate          Migrate configuration/metadata/layout from
                previous versions of git-svn
                     --config-dir 
                     --ignore-paths 
                     --ignore-refs 
                     --include-paths 
                     --minimize 
                     --no-auth-cache 
                     --username 
  mkdirs           recreate empty directories after a checkout
                     --revision, -r 
  propget          Print the value of a property on a file or directory
                     --revision, -r 
  proplist         List all properties of a file or directory
                     --revision, -r 
  propset          Set the value of a property on a file or directory - will be set on commit
  rebase           Fetch and rebase your working directory
                     --add-author-from 
                     --authors-file, -A 
                     --authors-prog 
                     --config-dir 
                     --dry-run, -n 
                     --fetch-all, --all 
                     --follow-parent, --follow! 
                     --ignore-paths 
                     --ignore-refs 
                     --include-paths 
                     --localtime 
                     --local, -l 
                     --log-window-size 
                     --merge, -m, -M 
                     --no-auth-cache 
                     --no-checkout 
                     --preserve-merges, -p 
                     --quiet, --q+ 
                     --repack-flags, --repack-args, --repack-opts 
                     --repack 
                     --strategy, -s 
                     --use-log-author 
                     --username 
                     --verbose, -v 
  reset            Undo fetches back to the specified SVN revision
                     --parent, -p 
                     --revision, -r 
  set-tree         Set an SVN repository to a git tree-ish
                     --add-author-from 
                     --authors-file, -A 
                     --authors-prog 
                     --config-dir 
                     --copy-similarity, -C 
                     --edit, -e 
                     --find-copies-harder 
                     --follow-parent, --follow! 
                     --ignore-paths 
                     --ignore-refs 
                     --include-paths 
                     -l 
                     --localtime 
                     --log-window-size 
                     --no-auth-cache 
                     --no-checkout 
                     --quiet, --q+ 
                     --repack-flags, --repack-args, --repack-opts 
                     --repack 
                     --rmdir 
                     --stdin 
                     --use-log-author 
                     --username 
  show-externals   Show svn:externals listings
                     --revision, -r 
  show-ignore      Show svn:ignore listings
                     --revision, -r 
  tag              Create a tag in the SVN repository
                     --commit-url 
                     --destination, -d 
                     --dry-run, -n 
                     --message, -m 
                     --parents 
                     --username 
GIT_SVN_ID may be set in the environment or via the --id/-i switch to an
arbitrary identifier if you're tracking multiple SVN branches/repositories in
one git repository and want to keep them separate.  See git-svn(1) for more
information.
user@hostname:~/repositories/app$ 

It means that the ‘git’ command is available for further usage. In this context, it is for cloning source code application from SVN repository.

2. Using the appropriate address of SVN repository, type the following command to start cloning the source code :

git svn clone https://xxx.xxx.xxx directory_target
Description : 
git svn : Command for performing any operations related with SVN Repository  
clone : Parameter for initializing source code fetched.
https://xxx.xxx.xxx : URL of SVN Repository   
directory_target : Directory created to store the cloned source code

For an example, the following is the output of ‘git’ command execution. It is followed by ‘svn’ keyword as additional parameter :

user@hostname:~/repositories/app$ git svn clone http://xxx.xxx.xxx/myrepo/app/module/ module
Initialized empty Git repository in /home/user/repositories/app/module/.git/
Authentication realm: <http://xxx.xxx.xxx:80> My Repository
Password for 'user': 
...
...
...
Checked out HEAD:
  http://xxx.xxx.xxx/myrepo/app/module r160
...
user@hostname:~/repositories/app$

As shown in the above output, by default the user used for cloning will be the user executes the command. On the contrary, as for another example below it is totally different with the additional parameter -user :

user@hostname:~/repositories/app$ git svn --user myuser clone http://xxx.xxx.xxx/myrepo/app/module/ module
Initialized empty Git repository in /home/user/repositories/app/module/.git/
Authentication realm: <http://xxx.xxx.xxx:80> My Repository
Password for 'myuser': 
...
...
...
Checked out HEAD:
  http://xxx.xxx.xxx/myrepo/app/module r160
...
user@hostname:~/repositories/app$

If nothing goes wrong with the above process, the source code located in http://xxx.xxx.xxx/myrepo/app/module/ will be cloned in a folder named module.

Leave a Reply