threads / discuss / 24319

Handling tags/branches after git-svn fetch during SVN to Git conversion

Subject: Handling tags/branches after git-svn fetch during SVN to Git conversion

## tl;dr

7 messages between Jul 7, 2010 and Jul 9, 2010.

replies: 6people: 2as markdown or json

Bradley Wagner· Jul 7, 2010, 13:36 UTC · lore

I had a fairly complicated config for my SVN to Git migration with multiple branch and tag locations. Therefore, I had to break up the "git svn clone" because I didn't know how to pass multiple branch locations to "git svn clone":

1. git svn init
2. Update .git/config with branch/tag locations
[svn-remote "svn"]
        url = file:///Users/Developers/git_transition/svn_repo
        fetch = project/trunk:refs/remotes/svn/trunk
        branches =
project/branches/{feature1-branch,feature2-branch}:refs/remotes/svn/*
        branches =
project/branches/{6.x,5.x,4.x,3.x,archive}/*:refs/remotes/svn/*
        tags = project/tags/{3.7.x,4.x,5.x,6.x,old-releases}/*:refs/remotes/svn/tags/*
3. git svn -A/path/to/mappings fetch

Do I need to convert these remote tags/branches into local Git tags/branches before pushing them to my remote Git repo or is there a way to push remote branches directly to my remote Git repo?

The command that someone else told me was "git checkout -b <local_branch_name> <remote_branch_name>". Though, I've seen other places mention different strategies for converting the branches.

The script I devised to convert the tags does this for each tags folder to maintain the original commit date, author, and commit message:

git for-each-ref --format="%(refname)" refs/remotes/svn/tags/6.x | grep -v @ | while read tag; do GIT_COMMITTER_DATE="$(git log -1 --pretty=format:"%ad" "$tag")" GIT_COMMITTER_EMAIL="$(git log -1 --pretty=format:"%ce" "$tag")" GIT_COMMITTER_NAME="$(git log -1 --pretty=format:"%cn" "$tag")" git tag -m "$(git log -1 --pretty=format:"%s%n%b" "$tag")" ${tag#refs/remotes/svn/tags/6.x/} "$tag"; done

Please let me know if this is correct.
Thanks!
Bradley Wagner· Jul 9, 2010, 02:33 UTC · re: Bradley Wagner · lore

Re: Handling tags/branches after git-svn fetch during SVN to Git conversion

I posted this question to StackOverflow and got back that I should use the svn2git tool. Surely there has to be a native way to convert these branches into local branches using git-svn.

http://stackoverflow.com/questions/3206383/what-is-the-correct-way-to-convert-svn-remote-branches-and-tags-into-local-git-br

On Wed, Jul 7, 2010 at 9:36 AM, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:

Show 41 quoted lines
>
> I had a fairly complicated config for my SVN to Git migration with
> multiple branch and tag locations. Therefore, I had to break up the
> "git svn clone" because I didn't know how to pass multiple branch
> locations to "git svn clone":
>
> 1. git svn init
> 2. Update .git/config with branch/tag locations
> [svn-remote "svn"]
>        url = file:///Users/Developers/git_transition/svn_repo
>        fetch = project/trunk:refs/remotes/svn/trunk
>        branches =
> project/branches/{feature1-branch,feature2-branch}:refs/remotes/svn/*
>        branches =
> project/branches/{6.x,5.x,4.x,3.x,archive}/*:refs/remotes/svn/*
>        tags = project/tags/{3.7.x,4.x,5.x,6.x,old-releases}/*:refs/remotes/svn/tags/*
> 3. git svn -A/path/to/mappings fetch
>
> Do I need to convert these remote tags/branches into local Git
> tags/branches before pushing them to my remote Git repo or is there a
> way to push remote branches directly to my remote Git repo?
>
> The command that someone else told me was "git checkout -b
> <local_branch_name> <remote_branch_name>". Though, I've seen other
> places mention different strategies for converting the branches.
>
> The script I devised to convert the tags does this for each tags
> folder to maintain the original commit date, author, and commit
> message:
>
> git for-each-ref --format="%(refname)" refs/remotes/svn/tags/6.x |
> grep -v @ | while read tag; do GIT_COMMITTER_DATE="$(git log -1
> --pretty=format:"%ad" "$tag")" GIT_COMMITTER_EMAIL="$(git log -1
> --pretty=format:"%ce" "$tag")" GIT_COMMITTER_NAME="$(git log -1
> --pretty=format:"%cn" "$tag")" git tag -m "$(git log -1
> --pretty=format:"%s%n%b" "$tag")" ${tag#refs/remotes/svn/tags/6.x/}
> "$tag"; done
>
> Please let me know if this is correct.
>
> Thanks!

-- Hannon Hill - Put Us to the Test bradley.wagner@hannonhill.com | http://www.hannonhill.com

Jacob Helwig· Jul 9, 2010, 02:54 UTC · re: Bradley Wagner · lore

Re: Handling tags/branches after git-svn fetch during SVN to Git conversion

On Wed, Jul 7, 2010 at 06:36, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:

> Do I need to convert these remote tags/branches into local Git
> tags/branches before pushing them to my remote Git repo or is there a
> way to push remote branches directly to my remote Git repo?
>

You don't need to "convert" the branches to local ones. git-push will accept any ref your local repo knows about when you do a push. For example "git push remote2 origin/branch-foo:refs/heads/branch-foo" works just fine, even if you don't have a "local" branch called "branch-foo", and it will push the branch-foo branch out to the remote2 remote repository.

The tags, you'll need to convert to _actual_ tags, instead of just branches under a tags/ namespace. Unless you're fine with them staying as pseudo-tags, then you can just push them out as you would any other branch.

-Jacob
Bradley Wagner· Jul 9, 2010, 03:01 UTC · re: Jacob Helwig · lore

Re: Handling tags/branches after git-svn fetch during SVN to Git conversion

In your example, does "remote2" represent the name of my remote Git repo? What is "origin/branch-foo" and does the path "refs/heads/branch-foo" need to actually exist in my .git directory?

On Thu, Jul 8, 2010 at 10:54 PM, Jacob Helwig <jacob.helwig@gmail.com> wrote:
Show 21 quoted lines
> On Wed, Jul 7, 2010 at 06:36, Bradley Wagner
> <bradley.wagner@hannonhill.com> wrote:
>> Do I need to convert these remote tags/branches into local Git
>> tags/branches before pushing them to my remote Git repo or is there a
>> way to push remote branches directly to my remote Git repo?
>>
>
> You don't need to "convert" the branches to local ones.  git-push will
> accept any ref your local repo knows about when you do a push.  For
> example "git push remote2 origin/branch-foo:refs/heads/branch-foo"
> works just fine, even if you don't have a "local" branch called
> "branch-foo", and it will push the branch-foo branch out to the
> remote2 remote repository.
>
> The tags, you'll need to convert to _actual_ tags, instead of just
> branches under a tags/ namespace.  Unless you're fine with them
> staying as pseudo-tags, then you can just push them out as you would
> any other branch.
>
> -Jacob
>
-- 
Hannon Hill - Put Us to the Test
bradley.wagner@hannonhill.com | http://www.hannonhill.com
Jacob Helwig· Jul 9, 2010, 03:09 UTC · re: Bradley Wagner · lore

Re: Handling tags/branches after git-svn fetch during SVN to Git conversion

remote2 would be the name of your remote repo, yes.

origin/branch-foo would be equivalent to svn/branch-foo in your local repo, if you did "git branch -a". It should be the name of one of the git-svn created branches.

refs/heads/branch-foo is telling git where to store the reference for the branch within remote2. It does not need to exist already, and should not in your case.

The git-push man page has more in-depth explanations, if you're interested.

On Thu, Jul 8, 2010 at 20:01, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:

Show 33 quoted lines
> In your example, does "remote2" represent the name of my remote Git
> repo? What is "origin/branch-foo" and does the path
> "refs/heads/branch-foo" need to actually exist in my .git directory?
>
> On Thu, Jul 8, 2010 at 10:54 PM, Jacob Helwig <jacob.helwig@gmail.com> wrote:
>> On Wed, Jul 7, 2010 at 06:36, Bradley Wagner
>> <bradley.wagner@hannonhill.com> wrote:
>>> Do I need to convert these remote tags/branches into local Git
>>> tags/branches before pushing them to my remote Git repo or is there a
>>> way to push remote branches directly to my remote Git repo?
>>>
>>
>> You don't need to "convert" the branches to local ones.  git-push will
>> accept any ref your local repo knows about when you do a push.  For
>> example "git push remote2 origin/branch-foo:refs/heads/branch-foo"
>> works just fine, even if you don't have a "local" branch called
>> "branch-foo", and it will push the branch-foo branch out to the
>> remote2 remote repository.
>>
>> The tags, you'll need to convert to _actual_ tags, instead of just
>> branches under a tags/ namespace.  Unless you're fine with them
>> staying as pseudo-tags, then you can just push them out as you would
>> any other branch.
>>
>> -Jacob
>>
>
>
>
> --
> Hannon Hill - Put Us to the Test
> bradley.wagner@hannonhill.com | http://www.hannonhill.com
>
Bradley Wagner· Jul 9, 2010, 03:18 UTC · re: Jacob Helwig · lore

Re: Handling tags/branches after git-svn fetch during SVN to Git conversion

Thanks. Yea I was just looking at the man page trying to find the notation with the colon separated ref names.

Is ":refs/heads/branch-foo" equivalent to just saying ":branch-foo" in the remote Git repo? Do I need the refs/heads piece?

I'm trying to understand what a usual "git push origin branch-foo" equates to using your syntax.

On Thu, Jul 8, 2010 at 11:09 PM, Jacob Helwig <jacob.helwig@gmail.com> wrote:
Show 39 quoted lines
> remote2 would be the name of your remote repo, yes.
>
> origin/branch-foo would be equivalent to svn/branch-foo in your local
> repo, if you did "git branch -a".  It should be the name of one of the
> git-svn created branches.
>
> refs/heads/branch-foo is telling git where to store the reference for
> the branch within remote2.  It does not need to exist already, and
> should not in your case.
>
> The git-push man page has more in-depth explanations, if you're interested.
>
> On Thu, Jul 8, 2010 at 20:01, Bradley Wagner
> <bradley.wagner@hannonhill.com> wrote:
>> In your example, does "remote2" represent the name of my remote Git
>> repo? What is "origin/branch-foo" and does the path
>> "refs/heads/branch-foo" need to actually exist in my .git directory?
>>
>> On Thu, Jul 8, 2010 at 10:54 PM, Jacob Helwig <jacob.helwig@gmail.com> wrote:
>>> On Wed, Jul 7, 2010 at 06:36, Bradley Wagner
>>> <bradley.wagner@hannonhill.com> wrote:
>>>> Do I need to convert these remote tags/branches into local Git
>>>> tags/branches before pushing them to my remote Git repo or is there a
>>>> way to push remote branches directly to my remote Git repo?
>>>>
>>>
>>> You don't need to "convert" the branches to local ones.  git-push will
>>> accept any ref your local repo knows about when you do a push.  For
>>> example "git push remote2 origin/branch-foo:refs/heads/branch-foo"
>>> works just fine, even if you don't have a "local" branch called
>>> "branch-foo", and it will push the branch-foo branch out to the
>>> remote2 remote repository.
>>>
>>> The tags, you'll need to convert to _actual_ tags, instead of just
>>> branches under a tags/ namespace.  Unless you're fine with them
>>> staying as pseudo-tags, then you can just push them out as you would
>>> any other branch.
>>>
>>> -Jacob
Jacob Helwig· Jul 9, 2010, 03:34 UTC · re: Bradley Wagner · lore

Re: Handling tags/branches after git-svn fetch during SVN to Git conversion

On Thu, Jul 8, 2010 at 20:18, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:

Show 6 quoted lines
> Thanks. Yea I was just looking at the man page trying to find the
> notation with the colon separated ref names.
>
> Is ":refs/heads/branch-foo" equivalent to just saying ":branch-foo" in
> the remote Git repo? Do I need the refs/heads piece?
>

That really depends on whether or not branch-foo already exists or not. From what I remember, if you use the <local>:<remote> syntax, then you need the refs/heads bit if the branch doesn't already exist.

> I'm trying to understand what a usual "git push origin branch-foo"
> equates to using your syntax.
>
It's equivalent to:
  git push origin refs/heads/branch-foo:refs/heads/branch-foo
  git push origin branch-foo:refs/heads/branch-foo
  # If branch-foo already exists on the remote end, it's also the same as:
  git push origin refs/heads/branch-foo:branch-foo
  git push origin branch-foo:branch-foo
Show 41 quoted lines
> On Thu, Jul 8, 2010 at 11:09 PM, Jacob Helwig <jacob.helwig@gmail.com> wrote:
>> remote2 would be the name of your remote repo, yes.
>>
>> origin/branch-foo would be equivalent to svn/branch-foo in your local
>> repo, if you did "git branch -a".  It should be the name of one of the
>> git-svn created branches.
>>
>> refs/heads/branch-foo is telling git where to store the reference for
>> the branch within remote2.  It does not need to exist already, and
>> should not in your case.
>>
>> The git-push man page has more in-depth explanations, if you're interested.
>>
>> On Thu, Jul 8, 2010 at 20:01, Bradley Wagner
>> <bradley.wagner@hannonhill.com> wrote:
>>> In your example, does "remote2" represent the name of my remote Git
>>> repo? What is "origin/branch-foo" and does the path
>>> "refs/heads/branch-foo" need to actually exist in my .git directory?
>>>
>>> On Thu, Jul 8, 2010 at 10:54 PM, Jacob Helwig <jacob.helwig@gmail.com> wrote:
>>>> On Wed, Jul 7, 2010 at 06:36, Bradley Wagner
>>>> <bradley.wagner@hannonhill.com> wrote:
>>>>> Do I need to convert these remote tags/branches into local Git
>>>>> tags/branches before pushing them to my remote Git repo or is there a
>>>>> way to push remote branches directly to my remote Git repo?
>>>>>
>>>>
>>>> You don't need to "convert" the branches to local ones.  git-push will
>>>> accept any ref your local repo knows about when you do a push.  For
>>>> example "git push remote2 origin/branch-foo:refs/heads/branch-foo"
>>>> works just fine, even if you don't have a "local" branch called
>>>> "branch-foo", and it will push the branch-foo branch out to the
>>>> remote2 remote repository.
>>>>
>>>> The tags, you'll need to convert to _actual_ tags, instead of just
>>>> branches under a tags/ namespace.  Unless you're fine with them
>>>> staying as pseudo-tags, then you can just push them out as you would
>>>> any other branch.
>>>>
>>>> -Jacob
>

← back to recent threads