Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git-svn: create & push a new branch/tag?

Tags:

git

git-svn

After cloning an SVN repository using git-svn with the -s option (git svn clone http://server/repo -s), how does one create a branch or tag and have pushed to the relevant branch/tag directory in the repository when dcommiting?

For instance; if I were to use git to create a foobar branch locally (git checkout -b foobar) how can I have git-svn create the branch on the server (http://server/repo/branches/foobar)?

I'm using Git 1.5.5.6.


Please Note:

The accepted method below does not work with Git 1.5.5.6 as there is no git svn branch method. I'm still looking for a solution to this that doesn't involve resolving to working with svn directly.

like image 464
Phillip B Oldham Avatar asked Mar 22 '10 08:03

Phillip B Oldham


People also ask

Can you use Git with SVN?

The git-svn tool is an interface between a local Git repository and a remote SVN repository. Git-svn lets developers write code and create commits locally with Git, then push them up to a central SVN repository with svn commit-style behavior.

What is Git SVN clone?

git svn clone checks out each SVN revision, one by one, and makes a git commit in your local repository in order to recreate the history. If the SVN repository has a lot of commits this will take a while, so you may want to grab a coffee.

How do I clone a SVN code?

# Clone a repo with standard SVN directory layout (like git clone): git svn clone http://svn.example.com/project --stdlayout --prefix svn/ # Or, if the repo uses a non-standard directory layout: git svn clone http://svn.example.com/project -T tr -b branch -t tag --prefix svn/ # View all branches and tags you have ...


2 Answers

You can read all the nitty-gritty details in this tutorial, but the gist is basically the following:

$ git svn branch -m "Topic branch" my_topic            # Create SVN branch called "my_topic" $ git checkout --track -b my-topic remotes/my_topic    # Create the Git branch for "my_topic" # Hack hack hack... $ git svn dcommit --dry-run    # Make sure you're committing to the right SVN branch $ git svn dcommit              # Commit changes to "my_topic" branch in SVN 
like image 137
mipadi Avatar answered Sep 18 '22 10:09

mipadi


If you created your local branch before the subversion branch existed and you now want to push your local branch into a subversion branch, you can do the following:

Obtain the svn branch revision assigned to the local branch

$ git svn info

from the output, URL field would be the current svn branch path and Revision field would be the subversion revision number

Create the svn branch from the revision that you created your local branch

$ svn cp http://svn-repo/my_app/trunk@123 http://svn-repo/my_app/branches/feature1

Fetch the new svn branch so that your git repo knows about it

$ git svn fetch

The svn branch should now be added as a remote in your git repo $ git branch -a * feature1 master remotes/feature1

At this point your remote will still be trunk. You need to point your local branch to the new remote branch. You can do this by rebasing your local branch from the remote branch: $ git rebase remotes/feature1

Now that your local branch refer to your remote branch, you can commit your changes onto it. First do a dry run so you are confident that your changes will go into your remote branch: $ git svn dcommit --dry-run Commiting to http://svn-repo/my_app/branches/feature1

Now you may commit changes to your remote branch $ git svn dcommit

Most how-tos will tell you to branch subversion first and then create a local branch which tracks the remote branch. But I often don't decide ahead of time whether my local branch should track a remote branch. Often I branch locally, and make changes without any intention of pushing to a remote branch. If I later decide to commit my local branch into a remote branch I perform the steps above.

like image 33
pestrella Avatar answered Sep 22 '22 10:09

pestrella