14

I'm using git-tfs, and I was wondering if it is possible to merge two TFS branches using git-tfs. I have two branches $/MyCompany/Dev & $/MyCompany/Release-3.3. Release-3.3 originates from the Dev branch. Both are checked out as different git repositories using git tfs.

I'd like to re-incorporate the changes back into the Dev branch. Can this be achieved with git-tfs or will I have to resort to trying to do it using TFS tools?

Philippe
  • 28,207
  • 6
  • 54
  • 78
Ceilingfish
  • 5,397
  • 4
  • 44
  • 71

3 Answers3

10

Since git-tfs 0.16, you can manage TFS branches (with branch command) so you can now easily init existing branch, create one and merge TFS branches!

https://github.com/git-tfs/git-tfs/blob/master/doc/commands/branch.md#initialize-an-existing-tfs-branch

And since the release 0.19, you can do a git merge of 2 TFS branches and checkin it in TFS (with rcheckin) and it will be checked in as a merge changeset : https://github.com/git-tfs/git-tfs/blob/master/doc/commands/rcheckin.md#checkin-a-merge-changeset

The only limitation (due to TFS) is that all the commits should have been already checked in TFS before doing your merge with git and check it in TFS.

So you can now merge more easily than with 2TFS branches and check them in...

Mark F Guerra
  • 892
  • 10
  • 13
Philippe
  • 28,207
  • 6
  • 54
  • 78
  • Note that as of 30-Sep-2013, the documentation indicates that `init-branch` is deprecated in favour of `branch --init` – David Gardiner Oct 25 '13 at 07:39
  • @DavidGardiner your right but the 2 are equivalent (the one is a wrapper for the other) and the command won't be removed until 0.20 (and the 0.19 is still not release). – Philippe Oct 25 '13 at 10:18
  • No worries.. I think we can assume you're a good source for git-tfs info :-) – David Gardiner Oct 25 '13 at 12:32
6

I found an awesome, if hacky way of doing this. Git tfs manages it's awareness of areas of TFS using git config. Specifically 3 attributes per remote; url, repository and fetch, for example:

tfs-remote.default.url=http://tfsserver:8080/tfs/collection
tfs-remote.default.repository=$/Product/Branch/Component
tfs-remote.default.fetch=refs/remotes/default/master

You can add another remote by setting these 3 properties again with a different name to default. Eg:

tfs-remote.feature_branch.url=http://tfsserver:8080/tfs/collection
tfs-remote.feature_branch.repository=$/Product/FeatureBranch/Component
tfs-remote.feature_branch.fetch=refs/remotes/default/feature_branch

You may need to issue git tfs bootstrap now.

You can then issue:

git tfs fetch -i feature_branch

Then merge the commits using:

git merge tfs/feature_branch
CincauHangus
  • 431
  • 3
  • 21
Ceilingfish
  • 5,397
  • 4
  • 44
  • 71
  • 1
    Does this actually create a merge pending change in TFS? If not, you're sort of hosing the next person who wants to do a merge from a TFS client, because TFS will not have recorded the merge as having been performed. Thus, it will try to merge those changesets again. (Admittedly, the conflicts will be fairly trivial, but it could still be annoying.) – Edward Thomson Feb 07 '12 at 19:08
  • You're quite right, this mechanism would cause issues if there were more than one user merging branches. I may have found a better solution here: http://stackoverflow.com/a/7334268/58991 – Ceilingfish Feb 07 '12 at 21:15
  • Does anyone know if git-tf (not git-tfs) allows this kind of merging? Does the checkin occur as a merge or just as new code? – Sebastien Martin Sep 06 '12 at 15:39
  • 1
    @SebastienMartin Now it's possible with the dev version of git-tfs (and will be possible with version 0.19). See my reponse below... – Philippe Oct 25 '13 at 10:30
-1

I'm not a git-tfs user, but I have done this with git-svn in the past (which I believe has a similar approach). I think your main issue is that you have two repos. If you add both remote branches to the same git repo, you should then be able to do a local merge, do a local commit and then push that commit to TFS.

HTH

Sebastien Martin
  • 1,341
  • 11
  • 25