Skip to content

Instantly share code, notes, and snippets.

@ejpcmac
Last active February 10, 2025 21:17
Show Gist options
  • Save ejpcmac/d624a7cdb2196bc5dea357a95b18a56c to your computer and use it in GitHub Desktop.
Save ejpcmac/d624a7cdb2196bc5dea357a95b18a56c to your computer and use it in GitHub Desktop.
git-svn cheatsheet

git-svn cheatsheet

Clone a repo with selected branches + git worktree layout

  1. Create the directory for git worktrees:

     mkdir repo_name
     cd repo_name
    
  2. Init a repo:

     git svn init https://path/to/svn/repo_name --username=<username> --trunk=branches/main_branch main_branch
    
  3. Edit repo_name/main_branch/.git/config so that it contains something like:

    [svn-remote "svn"]
      url = "https://path/to/svn/repo_name"
      fetch = "branches/main_branch:refs/remotes/svn/main_branch"

    Add more fetch keys to fetch more branches

  4. Inspect the SVN log to find a first revision:

     svn log https://path/to/svn/repo_name -l <max-depth>
    
  5. Fetch that revision:

     git svn fetch -r<revision>
    
  6. Fetch all newer revisions:

     git svn fetch
    

Re-create the git-svn history from an older revision

  1. Delete .git/refs/remotes/svn.
  2. Delete .git/svn
  3. Run git svn fetch -r<revision>.
  4. Run git svn fetch.
  5. Rebase local branches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment