In these days I’ve heard lot of rumors around Git. After reading some manual/tutorial/guide I discovered that it can be really useful, especially if you spend lot of time coding off-line (that’s my situation).
This is a really small howto that describes how to work on a project versioned with svn (maybe taken from KDE repository
) using git.
What’re the advantages?
Since Git is a distributed revision control system (while svn is a centralized one) you can perform commits, brances, merges,… on your local working dir without being connected to internet.
Next time you’ll be online, you will be able to “push” your changes back to the central svn server.
Steps to follow:
You’ve to:
- install git and git-svn
- create the working dir:
mkdir strigi - init your git working dir:
cd strigi && git-svn init https://svn.kde.org/home/kde/trunk/kdesupport/strigi
git-svn init command is followed by the address of the svn repository (in this case we point to strigi’s repository) - Find a commit regarding the project (you can get it from cia version control). Warning: the command git-log will show project’s history starting from this revision.
- Perform the command
git-svn fetch -rREVISION
Where REVISION is the number obtained before. - Update your working dir:
git-svn rebase
Now you’ll be able to work on your project using git as revision control system.
To keep update your working copy just perform:
git-svn rebase
You can commit your changes to the svn server using the command:
git-svn dcommit
In this way each commit made with git will be “transformed” into a svn one.
Solve git-svn rebase problems
While adding new cool features to your program, you may experiment some problem when synchronizing with the main development tree. In fact you have to commit all local modifications (using the git-commit command) before invoking git-svn rebase.
Sometimes it isn’t reasonable since your changes are not yet ready to be committed (you haven’t finished/tested/improved your work). But don’t worry, git has a native solution also for this problem, just follow these steps:
- put aside your changes using the command:
git-stash - update your working copy using:
git-svn rebaseas usual - take back your changes typing:
git-stash apply - clear “the stash” typing:
git-stash clear
After the first step all your uncommitted changes will disappear from the working copy, so you’ll be able to perform the rebase command without problems.
For further informations read git-stash man page.
That’s all.
Greetings: I would like to thank Thiago Macieira for his help.
Tags: Howto, KDE, Programming














Entries (RSS)
Really? The git commits do not get merged into one SVN commit? So git-svn preserves my local (git) history? That is cool!
[...] there’s a “cleaner” solution, if you’re interested read the last part of my git-svn howto. Tags: , git, Howto, KDE, [...]
[...] these instructions exist in one piece anywhere else. UPDATE: As it turns out, I practically stole this. Flavio’s version is better anyways. I recommend his blog to all KDE [...]
How to create a tag in svn-repository using git-svn/git?
[...] Howto use Git and svn together | Flavio Castelli [...]
Thanks this is a pretty cool tool.
Hi Flavio,
Would you be willing to copy this onto Techbase?
Yes, I can do it.
I’ll copy it as soon as possible.
nevermind. I just found http://techbase.kde.org/Development/Tutorials/Git
you might review that tutorial and see if there’s anything to add
sure!
[...] Actualmente uso GIT y estoy aprendiendo más sobre el, a mi gusto es muy rápido y me da muchas libertades aun pesar de no ser centralizado, espero en un futuro se integre más a los IDE’s pero mientras tanto estoy contento con la línea de comando, por si su equipo usa SVN, aquí un tutorial de como usar GIT mientras tu equipo usa SVN, GIT+SVN [...]
[...] a good’un. Thanks to Flavio Castelli Possibly related posts: (automatically generated)Partial git clone of SVN subdirectoryGIT – The [...]
[...] How to Use Git with SVN — A blog article showing how to use git when interacting with an existing svn repository. [...]
Actually the second step did not exactly behave as you described.
When I did a ‘git-svn fetch -rREVISION’ ,
‘git log ‘ shows only the comment for that revision. Not all the revisions starting from that revision as you implied. Which is the behaviour I want too.
Any ideas?
after doing ‘git-svn fetch -rREVISION’ you have to run ‘git-svn rebase’
Just an FYI for others – if you experience any errors after running “git svn init” (such as a closed connection during a big import), you can continue with your import using:
“git svn fetch”
Great article. Git is now my svn client.
One question. Why can’t i do `git svn fetch` instead of `git svn rebase` for synchronizing with the main development tree?
Because you most times only want to quickly get the latest revisions and worry about merge problems later; use fetch. With rebase you first fetch and then merge HEAD with your working tree, with possible merge problems.
[...] transferred all my repos over from Subversion to Git and have become familiar enough with the Git SVN bindings to even work on my work projects in Git while still being able to check-in as a regular SVN [...]
Hi, I’m working in a project that is officially maintained in a SVN repository. What I’m doing now is the following:
1) make local copy using ‘git svn clone’ from the SVN repository (which I delete after (2)).
2) make local copy again to a different directory using just ‘git clone’ from (1).
3) since I work in different computers (work/home/laptop) I have a local git-repository in each of them that I maintain doing pulls from one to another every time I switch computer.
4) in the meantime the SVN repository gets updated by other people contributions.
Now in order to merge all the changes I’ve been working on with the latest version of the SVN repository I do the following:
1) I get a fresh copy of the SVN repository using ‘git svn clone’ (new directory)
2) pull it from the latest local git-repository using ‘git pull –rebase’
3) fix all the conflicts and continue merging until is done.
4) pull the new merged version into the SVN copy with ‘git pull’
(this runs smoothly — no complains at all)
5) upload the changes to the SVN repository using ‘git svn dcommit’
I found this procedure really messy. Is there any other more-cleaner way to do this ?
Thanks a lot,
Fernando
I follow this procedure :
1. git svn clone on the server
2. git clone on my local machine
Do all the development on the local repository
To keep track of latest version of repository I do :
1. git svn init
2. git svn fetch
3. git svn rebase
Hope this helps
[...] en forma rotunda por su velocidad y poca utilización de espacio extra en el disco*. Acá parece haber un tutorial cortito para utilizarlo (Google me devuelve muchísimos enlaces más por [...]
Wow Great article. Git is now my svn client.
One question. Why can’t i do `git svn fetch` instead of `git svn rebase` for synchronizing with the main development tree?
I like this article! Thanks
Would you be willing to copy this onto Techbase?
And is it good to use them together?
I was wondering if this would not be easier to work on its own branch
something like that
> git init ….
> git fetch -r 12345
> git rebase
> git checkout -b my_branch master
then .. work on your own branch using git
In the meantime, you can always update (rebase) the master branch
and when you are ready to commit, merge your changes to the master branch, and use the git svn dcommit.
It might be safer this way, … may be …
Any comment on this?
(Note that I am not currently using git svn, but I am thinking about it.)
Yeah, it can be safer.
Hi, I’m working in a project that is officially maintained in a SVN repository. What I’m doing now is the following:
1) make local copy using ‘git svn clone’ from the SVN repository (which I delete after (2)).
2) make local copy again to a different directory using just ‘git clone’ from (1).
Great article. Git is now my svn client.
One question. Why can’t i do `git svn fetch` instead of `git svn rebase` for synchronizing with the main development tree?
In fact, you can do “git svn fetch”. Of course you still need to rebase to do anything (on your local branch) with the changes you fetched.
Gr8 article.
[...] Howto use Git and svn together (Flavio Castelli) [...]
For some reason my browser doesn’t display this page correctly…However,
What combination of browser and OS are you using?
[...] http://flavio.castelli.name/howto_use_git_with_svn http://progit.org/book/ch8-1.html [...]
[...] Howto use Git and svn together | Flavio Castelli (tags: versioning git) [...]
[...] A blog post on git-svn (Git “interface” to a SVN repository) [...]
Fantastic!
So, I have my repo, but git svn rebase doesn’t always pull the latest from SVN. My git repo stays several svn revisions back, and I’m not sure why. I’ve wracked my head against the wall for a long time about it. Any ideas on what I’m doing wrong?
Are you sure your git repo is in a clean state? You cannot perform git svn rebase if you have some uncommitted changes.
Your post is smashing. There are some issues here but don’t have the time right now. I’m bookmarking this url and leave this comment to check again later and update my first comment (this one). By the way i found your blog as i was searching for similar subjects in Bing
[...] See this and this [...]
Awesome tutorial!
[...] strano motivo, l’integrazione del debugger degli IDE non mi è mai funzionato per bene. Git-SVN è un grande strumento: permette di usare Git per i depositi software SVN, come per KDE. Ho [...]
[...] Howto use Git and SVN together [...]
For those who want to set up a centralized Git-SVN repository, I’ve made a series of tutorial screencasts on how to use git-svn here:
http://www.tfnico.com/presentations/git-and-subversion
[...] blog post explains how to setup git with SVN when starting with a git repository. This other blog post discusses and solves some of the caveats that might occur with this [...]
[...] would I want to use Git? Flavio sums it up quite nicely: What’re the advantages? Since Git is a distributed revision control [...]
Great article, Flavio. I just linked to you. By the way, you and your readers might find the Facebook video link on my blog post interesting to watch – to see how Facebook does development – they’re crazy!
[...] is a description taken from here, which makes it clear as to what to do when Svn is updated and you need to update the local [...]
[...] This and this were very helpful in getting this working. Thanks! [...]
Instead of “git-stash apply” followed by “git-stash clear”, you should simply use “git-stash pop”. This has the advantage that it won’t destroy other stashes you have probably created.
[...] Howto use Git and svn together [...]
Now you may also consider using SubGit (http://subgit.com/) for using git and svn together without limiting yourself to git-svn boundaries.
Linux Tutorials…
[...]Howto use Git and svn together | Flavio Castelli[...]…
hi!,I love your writing so a lot! proportion we keep up a correspondence extra about your article on AOL? I need an expert on this house to solve my problem. Maybe that is you! Having a look forward to see you.
Hi,
Maybe you can help me in my problem. I wish to use in my projects git and svn together. The reason is complicated. We are making webpages and we have our own cms. Well, each webpage project is different, so I want to store them in SVN version control, in different projects. But each has the cms, with is common, that I want to store in other version control as a self standing project. The cms I would store in GIT.
My target is, that from any project I have to be able to commit in the repo of the website project and in the repo of the common cms as well.
Can I do this?
Thank you very much for your help!
Just stay with one scm, this will make your life easier. You can share the cms code using svn’s externals or using git’s submodules.
If you use svn as main cms you will still be able to checkout the code using git even when svn externals are used.
Hmm, don’t really understand…
Where should I store the CMS repo, and where the other projects’ repos?
just decide which scm to use. Then store the cms inside of a dedicated repo. Store the other projects inside of dedicated repositories and bring the scm code into them using svn externals or git submodules.
Hey, I tried following your instructions, but when I use “git svn rebase” I get this output:
fatal: ambiguous argument ‘HEAD’: unknown revision or path not in the working tree.
Use ‘–’ to separate paths from revisions
log –no-color –no-decorate –first-parent –pretty=medium HEAD: command returned error: 128
Any idea why that might be happening?
Happened to me too… it works if you use clone instead of init fetch.
git svn clone -s -r1234:HEAD http://some.svn.repo/repo repo
where 1234 is some revision in the svn repo.
[...] and subversion”和“Howto use Git and svn together”以及“git-svn [...]