tags:

views:

675

answers:

2

Hello,

I'm relatively new to Git, but I want to give it a try (vs SVN and Bazaar)

Can anyone recommend me a workflow for a situation similar to the following:

  • 1 SVN repo, with several projects
  • 1 working copy "src"

The ideea is that in "src" I need to checkout project A or sometimes project B. Both projects have several branches.

For now, I have made 2 git clones of the SVN repo, one for each project. (I would have preffered --bare repos, but it does not work with "git svn clone")

Then, I made a git repo in "src", and git remote add projA ..a_repo_git, "git remote add projB ..b_repo_git".

Now, I can see both of them from "src" using "git remote", and I can see their branches with "git remote show projA"

And now the trouble..

  • How can I get in "src" any of the branches in projA/projB ?
  • How can I modify them, and then be able to push them back (first to the git_repos, or directly to the SVN repo)?
  • Is this "workflow" ok, or do you have a better idea?

I did try in src: git checkout --track -b work_branch projA branch_in_A and after some fiddleing with "fetch" I managed to get the things. But then, I had problems pushing it back to the a_repo_git, and then to SVN. It was mostly trial and error.

I have to admit, I stil have problems with remote branches! (and I get lost when I have to use "origin local_branch:origin_branch" or "origin origin_branch:local_branch", or "origin origin_branch" or "origin/origin_branch"! Back to the Git manual for some more reading)

Thank you for any help.

Update: As someone proposed, there is no need for two extra repos that link each SVN project.

I've done the following:

mkdir src
cd src
git svn init --stdlayout --prefix=projA/ -RprojA file:///path/to/svn/repo/A
git svn init --stdlayout --prefix=projB/ -RprojB file:///path/to/svn/repo/B
vi .git/config -> update the svn-remote sections; I've left only the two with "projA" and "projB", but had to copy a line with fetch= from "svn" to "projA"
git svn fetch projA
git svn fetch projB

After this I could create a local branch with

git svn checkout -b my_branch projA/branch_name

(and "projA/branch_name" I think is the remote branch name + prefix, that appears with git branch -r)

So, basically now I have both svn projects linked in a single "workcopy" in "src", just like I've wanted. I can switch between the projects easily, in the same folder.

For now, I have not tried yet any push/pull, merge, or dcommit. I'll see into it later. Also, I want to investigate checkout using the "--track" option.

Thank you all who answered and commented here!

+1  A: 

Let us first consider the simpler case of one remote repo and one local repo.

A remote in the local repo works "only" as a reference to the other repo. You can use fetch to retrieve the remote objects to your local store:

git remote add upstream git://...
git fetch upstream

Now all branches from upstream can be locally referenced and worked on by using upstream/branchname. To really work on a remote branch, you should always make a local branch which tracks the remote branch:

git checkout -b new_local_branchname upstream/branchname

Now you can work locally and commit/merge as much as you like. As a final step you can push you changes back into the central repository. The imporant bit is that AFAIK push can only do fast-forward merges, that is upload the changes and set the new head. Therefore you have to prepare your local branch so that the local changes start on the tip of the remote branch. You can use rebase to achieve that or avoid changing the central repository while you are working locally.

This describes the simple workflow between two repositories. Now to the specific case with SVN.

git svn complicates the picture by further constraining the kind of changes you can do. As with remotes, you should never directly modify the svn branches but always work on a local branch. Unlike remotes, git svn always modifies commits as they go into the SVN repo to add the neccessary metadata. This last fact is probably the reason for many of your problems as commits on the SVN branch will always have different hashes from the original commits on your local branches.

Finally, your question about multiple projects in the same repo.

Git doesn't support parallel checkouts of multiple branches in the same repo. You might want to look into submodules to integrate multiple repos.

David Schmitt
Thank you for your explanation on working with a remote.I just gave a try to using a single git repo in "src", and add two remotes to projects A and B. Got in lots of problems (two trunks :D), too many mixed branches, etc. I will have a look at modules.Thank you
Alex
Good post. +1. May be http://stackoverflow.com/questions/572893/cloning-a-non-standard-svn-repository-with-git-svn/572898#572898 may have helped to obtain a "cleaner" branch hierarchy with Git... (and git2svn for pushing back the changes to svn)
VonC
This is helpful too http://stackoverflow.com/questions/572893/cloning-a-non-standard-svn-repository-with-git-svn/572898#572898 . I've now seen the "prefix" option, and this should help clarify which branch comes from where!
Alex
+2  A: 
Alex