How to synchronise between SVN and Git.
Tags: synchronisation, git, svn, migration
Published: 2023-02-05 15:34:06

---
title: How to synchronise between SVN and Git.
published: true
date: 2023-01-29 01:55:47 UTC
tags: synchronisation,git,svn,migration
canonical_url: https://medium.com/codex/how-to-synchronise-between-svn-and-git-a79602bb0df0
---

![](https://cdn-images-1.medium.com/max/1024/0*HF3lzp5MJ7wXaw7Y)
_Photo by Cas Holmes on Unsplash_

In my last post, I mentioned how one could migrate from SVN to Git. In this post, I will explain how to synchronise any changes between Git and Subversion (SVN) that may have occurred during the migration process.

There will always be that one person in your team that did not get the memo and committed some changes to SVN whilst you were in the middle of the migration. Don’t stress yourself out about it; there is a fix, and I will show you how.

The process is pretty straightforward and will include the following steps:

1) Creating a sync branch

2) Merge changes from SVN to Git

3) Optional: Merge changes from Git to SVN (if needed)

Please Note according to the [git svn documentation](https://git-scm.com/docs/git-svn#Documentation/git-svn.txt-emrebaseem) there is a command called git svn rebase. The _git svn rebase_command retrieves any changes made in the SVN repository and applies the changes to the current work within Git. This command is similar to svn update or git pull **however** , whenever I have tried to use this command in the past it would timeout on me. That is why I used the following process to sync the changes successfully. However, if this command works for you, please use it, yet if it does not, then continue reading.

### Create a sync branch

We will need to create a new branch within git, which we will call _svn\_sync_. This will allow us to pull any changes made from the main branch after the migration. Also, note that this branch will only be used to set up a connection to SVN, it will **not** be used for any development.

```
git branch --no-track svn_sync
```

Once the branch is created, checkout the branch and initialise the repository to the SVN repo. Once initialised, fetch the SVN repo making sure that the authors file that was used in the original migration is up-to-date.

```
git svn init -s https://mycompany.com/path/to/svn/repo
git svn fetch --authors-file=../authors.txt
```

If needed you can set the author’s file location so that you don’t have to type it out again.

```
git config svn-remote.svn.authorsfile ~/authors.txt
```

**_Optional_** _: If you had set up git LFS during the migration, you will need to perform the same setup in the new branch. If you need to remember how this is done, checkout the ‘Convert any large files to LFS objects’ section in my original post:_

[How to migrate SVN to Git](https://dev.to/melishatrout/how-to-migrate-svn-to-git-5hde)

### Merge changes from SVN to Git

Checkout the master branch and then merge the svn\_sync into master.

```
git checkout master
git merge svn_sync
```

Once everything is merged and there are no conflicts, you can now push the merge changes to the remote repository

```
git push origin master
```

### Optional: Merge changes from Git to SVN (if needed)

If you run into an issue whereby you would need to merge changes from git back to SVN then have fear! It’s just a simple process and I will help you through it.

First checkout the current release branch or the most up-to-date branch in git(this can be the master branch) and pull in the changes

```
git checkout master
git pull
```

Then you will need to checkout the svn\_sync branch and pull the latest changes:

```
git checkout svn_sync
git svn fetch
git svn rebase
```

Now you will need to merge the changes from the release or master branch into the svn\_sync branch:

```
git merge --no-ff master
```

If there are any conflicts, you will need to resolve them at this stage. Once they are resolved you will need to commit the changes locally and then commit the changes to SVN:

```
git commit -a
git svn commit
```

And there you have it, you have successfully synced between SVN and Git. I hope that this post was helpful. If you want to read more of my career advice and tech takes, consider following me as well as [signing up for my newsletter](https://meldevelle.medium.com/subscribe) so that you will never miss my post.

* * *