I have a git repository that was originally created using git-svn. Now I have a git server that I push to and the svn repository has been lost. Can I remove the svn remote? How?
4 Answers
You can edit the .git/config
file and remove the section associated with the remote you want to remove.
The lines you want to remove probably look roughly like this:
[svn-remote "svn"]
url = url-of-svn-repository/trunk
fetch = :refs/remotes/git-svn
This will remove the remote from Git, but you will still have the relationship between the Git commits and the SVN commits stored in .git/svn
. You can remove this whole directory if you want to get rid of all your SVN remotes. If you want to get rid of just one SVN remote and keep others, you will need to look at the directory structure and only remove the ones associated with the remote you are removing.
-
27Thanks Eric, I also had to remove the directory at `.git/svn`. – jlconlin Aug 21 '12 at 13:22
-
1Thanks - included in the answer now. – Eric Aug 21 '12 at 16:23
-
12I hapenned to find another reference inside `.git/refs/remote/git-svn`. It is a reference to the last commit from git-svn. – Rafael Raposo Apr 05 '13 at 23:59
Doing it via most *nix shells, bash or mingw32:
cd ~/your_repo
git config --remove-section svn
or whatever section you have when you view the config (cat .git/config
). For example, the next line would remove the same config section described in Eric's solution:
git config --remove-section svn-remote.svn
next remove all svn stuff inside the .git
folder (svn, logs, and refs). Which is also what Sergey suggests.
rm -rf .git/svn .git/{logs/,}refs/remotes/{git-,}svn/
garbage collection just for good measure:
git gc

- 1
- 1

- 10,437
- 2
- 40
- 57
-
My remote svn ref was stored as a file so I had to remove the trailing slash from the `rm` command, which is unneeded anyway. – rindeal Feb 24 '16 at 12:05
Eric's answer is correct, but not full. Even after Rafael Raposo's comment. I wish I could comment on the answer rather than posting a new one, but the rules are you can't comment until you reach 50 reputation.
The addition is:
find .git -type f -exec grep -nH git-svn "{}" \;
Showed me I had references in these two files:
./.git/info/refs:4:fd34a5c...8073f3 refs/remotes/git-svn
./.git/packed-refs:5:fd34a5...cd6c33 refs/remotes/git-svn
Until I removed those references, I could see git-svn doing git log

- 521
- 4
- 17
-
1
-
1I found that I had to go through the same process, but searching for “trunk” instead of “git-svn”, in order to get rid of the “origin/trunk” pseudo-branch. – bdesham Sep 11 '14 at 15:22
-
-
1I suspect you'd want to **cd** into **.git** and search for "git-svn" text in the files in there. As I mentioned, I found two of them - ".git/info/refs" and ".git/packed-refs". Open them in your favorite editor (don't use Notepad as it doesn't parse the stuff correctly and adds some garbage when you save). Open an editor and remove the lines referencing **git-svn**. – Sergey M Nov 26 '14 at 21:30
-
For Windows (for Linux too), you can skip the first code box, as it's just a stepping stone to find the `.git/info/refs` and `.git/packed-refs` files. – chronospoon Jan 05 '15 at 19:06
If you don't have any local config and you want to forego faffing about in the .git
directory, simply clone the git repo from the git remote to a new directory and remove the old directory.
If you do have some simple local config (for example a different user/email to your global config), it's probably still easier to do this, and then restore any local config after cloning.

- 18,461
- 9
- 58
- 95
-
Even after doing all the above cleanups, remote tracking branches from SVN still showed up. If a clean clone is an option, it's definitely way easier than anything else. – Martin Geisse Jul 25 '17 at 09:27
-
@MartinGeisse thanks - I have no idea why anyone bothers with all the other complicated answers for this problem, when this is a simple and effective solution. – jhabbott Jul 26 '17 at 10:25