Merge two TFS branches with git tfs
Asked Answered
Z

3

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?

Zoography answered 19/12, 2011 at 10:13 Comment(1)
I'd prefer to use the git merge algorithm, as it seems to resolve more conflicts automatically.Zoography
Z
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
Zoography answered 7/2, 2012 at 17:47 Comment(4)
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.)Steamy
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: https://mcmap.net/q/263104/-how-do-i-use-git-tfs-and-idiomatic-git-branching-against-a-tfs-repositoryZoography
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?Omarr
@SebastienMartin Now it's possible with the dev version of git-tfs (and will be possible with version 0.19). See my reponse below...Gasparo
G
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...

Gasparo answered 6/12, 2012 at 8:32 Comment(3)
Note that as of 30-Sep-2013, the documentation indicates that init-branch is deprecated in favour of branch --initJuliojulis
@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).Gasparo
No worries.. I think we can assume you're a good source for git-tfs info :-)Juliojulis
Z
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
Zoography answered 7/2, 2012 at 17:47 Comment(4)
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.)Steamy
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: https://mcmap.net/q/263104/-how-do-i-use-git-tfs-and-idiomatic-git-branching-against-a-tfs-repositoryZoography
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?Omarr
@SebastienMartin Now it's possible with the dev version of git-tfs (and will be possible with version 0.19). See my reponse below...Gasparo
O
-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

Omarr answered 9/1, 2012 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.