10

I've migrated a repo from SVN to Git using svn2git and am happy with everything apart from one thing. How can I remove the remotes/svn/trunk branch that shows in git branch -a:

$ git branch -a
* master
  remotes/origin/master
  remotes/svn/trunk

I cleaned up after svn2git by doing the following:

git config --remove-section svn-remote.svn
git config --remove-section svn
rm -rf .git/svn

But I still have the remotes/svn/trunk sitting there! I get this if I grep the .git directory for svn:

$ grep -R svn .git
.git/info/refs:e6dd7a08d86d9b0944891755602b25ce12d30bb0 refs/remotes/svn/trunk
Binary file .git/objects/pack/pack-10cdd522d8f0fcc9b30efeddbdad3d0281c1e6da.pack matches
.git/packed-refs:e6dd7a08d86d9b0944891755602b25ce12d30bb0 refs/remotes/svn/trunk

Am I safe to go into those files and remove the references or is there a cleaner way to get rid of that old cruft?

mattjgalloway
  • 34,372
  • 12
  • 95
  • 108

1 Answers1

11

Deleting the remote tracking branch would be a good start:

git branch -d -r svn/trunk

Other advices are available at "How do you stop tracking a remote branch in git?".
But to really clean, you may have to do other operations (based on git gc for instance) as mentioned in "How to remove unreferenced blobs from my git repo".

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Ugh, yeh that's the one. Should have known that really! I get slightly confused still with what a remote tracking branch is. Still very new to git! – mattjgalloway Jul 15 '12 at 12:03
  • @mattjgalloway : yes, it can be confusing ;) http://stackoverflow.com/questions/1070496/having-a-hard-time-understanding-git-fetch can help making this "remote tracking" business a bit clearer. – VonC Jul 15 '12 at 12:33
  • After trying `git branch -d -r svn/trunk`, I get "error: remote branch 'svn/trunk' not found.", yet it still shows in SourceTree under Remotes... Ideas? – Saran Nov 05 '13 at 09:17
  • @Saran what does `git remote -v` and `git br -avvv` return? – VonC Nov 05 '13 at 09:19
  • `git remote -v` returns nothing and `git branch -avvv` returns my branches w/o the (remote) svn/trunk one. – Saran Nov 05 '13 at 12:17
  • @Saran so your error message is coherent with your current local repo. A `svn2git` is supposed to declare a remote repo. – VonC Nov 05 '13 at 12:19
  • @VonC strange :) One more question: as mentioned in the question from mattjgalloway, is it safe to remove [svn-remote "svn"] and [svn] entries from the projects git config file in order to remove the remotes/Subversion entry I see in SourceTree? – Saran Nov 05 '13 at 13:23
  • @Saran it should be safe. But one technique I use when I don't like the internal state of a repo is... to clone it: I check I can still work from the clone (which shouldn't include any extra remote data this time). That way, I don't touch whatever repo I currently have: I clone and hack on the clone. – VonC Nov 05 '13 at 14:07
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/40566/discussion-between-saran-and-vonc) – Saran Nov 05 '13 at 14:07
  • @Saran: Had the same problem and @VonC's solution to make a local clone (`git clone old_path duplicate`) worked! – Bryan P Oct 21 '15 at 13:59