5

I have an issue attempting to pull my latest changes from TFS and adding them to a BitBucket repo. I have successfully pushed my branches into BitBucket, but when I attempt to get any new checkins from TFS I always get a merge conflict.

Steps:

  1. git tfs clone http://TFS-ADDRESS/Collection $/Project/Name/Branch
  2. git tfs init-branch $/Project/Name/NewBranch NewBranchName
  3. git push -u origin --all

At this point my BitBukcet repo has all my files and history from TFS. I then did a checking into me $/Project/Name/NewBranch on TFS.

Now I want to get the latest changesets from TFS and add/commit them into the BitBucket repository Note: At this point, no other branch in TFS or BitBucket has changed. The only change is my single check-in into TFS

When I do the following on my NewBranch, I get a merge conflict:

git tfs pull

Auto-merging Source/build.version
CONFLICT (content): Merge conflict in Source/build.version

As far as I can tell, it is trying to merge changes from my "master" to my "NewBranch", even though NewBranch is the latest code. The ptfs pull command is pulling the last checgeset down, but then tries to do the merge. If I use

git tfs fetch --all

I see the changeset listed, but I cannot commit/push it to the BitBucket repository. I cannot find a reference online to say what I am doing wrong, or what steps I need to take (I am new to Git). Can anyone help?

I eventually want to automate this so any check-ins in TFS can be fetched and added to the BitBucket repository (until we eventually move all developers to BitBucket)

Thanks

EDIT I am trying to take changes from TFS to BitBucket. Nothing is getting added to TFS from BitBucket.

All work is done on a branch (see below). Users are working in TFS. Users commit their changes there. NOTE: No-one is making edits to the BitBucket repo. It is a replica of TFS. Once a day, I want to pull the latest changesets for each TFS branch down to my local git folder and them push them into BitBucket. The "git tfs fetch" retrieves the changesets:

D:\development\workspaces\git\anothertry>git tfs fetch --all
C83419 = 3abdaedf571369dce15f74a52697d86069f87d6d

but "git status" tells me there is nothing to commit

D:\development\workspaces\git\anothertry>git status
# On branch Feature
nothing to commit, working directory clean

And when I try to push this changeset into BitBucket, git tells me there is nothing to commit.

Branches

Master---o---------------o----o--o-o--o-------
          \             /    /  / /  /
           Feature-----o----o--o-o--o
Simply Ged
  • 8,250
  • 11
  • 32
  • 40

3 Answers3

2

I seem to have found the answer after using Git Extensions.

It seems I need to do a fetch

git tfs fetch --all

This will get me all changesets from TFS for my trunk and any branches I have mapped (init-branch)

D:\development\workspaces\git\anothertry>git tfs fetch --all
C83454 = f65ba8d0cc7b40f42148ba2c06d0da8b7e968c4d
C83455 = 6c25feb6e74a09d0d3d84344002e7546044900ab
C83459 = 91c4450d702d5a97e862aedd7ad1b5af3ff2c375
C83460 = 5cacaba5bfe4197c1bf9fab498f51c1ba435e6ea

Next I need to perform a merge

git merge <guid>

NOTE: The is for the latest changeset (in this case 5cacaba...)

Updating 6c25feb..5cacaba
Fast-forward
 Source/Common/w32threads.h             | 1238 ++---
 Source/xxxxxxx_Service/ServerAgent.cpp | 3638 ++++++-------
 Source/xxxxxxx_Service/ServerAgent.h   |  449 +-
 Source/xxxxxxx_Service/User.cpp        | 9073 ++++++++++++++++----------------
 Source/xxxxxxx_Service/User.h          |  647 +--
 Source/build.version                   |    2 +-
 6 files changed, 7562 insertions(+), 7485 deletions(-)

And, finally, push my changes to BitBucket

git push --all

So, it seems I was missing the git merge call and the parameters to pass to it.

Cheers

Simply Ged
  • 8,250
  • 11
  • 32
  • 40
  • fetch --all is a little overkill (see all tfs remote to get changes and due to TFS, takes times) and your merge works only if your are in the good branch otherwise you will have something you don't expect! So "git tfs pull -r -i NewBranchName" will be better. Then push to bitbucket... PS : "pull" = "fetch" + "merge" – Philippe Apr 24 '13 at 14:53
0

I don't exactly understand what you do bad but there is somethings that you should now in using git-tfs...

  • Working with a TFS branch I see that you created a branch (step 2) and commit in that branch. When you have checkouted your branch 'NewBranchName', you should checkin with the command :

    git tfs rcheckin -i NewBranchName

and pull modifications with :

git tfs pull -i NewBranchName

or (with rebase)

git tfs pull -r -i NewBranchName

If you don't specify the -i option with the name of the TFS remote, you will check in your commit in the main branch (here, $/Project/Name/Branch ) :(

  • Checkin your commits on TFS I give you above the command to check in your commits. But you should know that, for some reasons, when you check in a git commit in TFS, a new changeset in TFS is created (that's what we want ;) ) and after a new git commit is created. It's nearly the same that the original but with some informations (that you can see in the git comment). Due to this fact, depending on what you do (and I don't exactly understand what), you could have problems because git try to merge commit with exactly the same modifications at the same place, so fail to merge automaticaly.

In fact, I think there is something wrong in your workflow because you shouldn't encounter this problem. Try to find the problem in your workflow.

I hope it will help.

Feel free to see the git-tfs wiki : https://github.com/git-tfs/git-tfs/wiki I hope there is quite useful informations (partly did it, with love ;) )

PS : To help you better, can you tell me which command you use to checkin your commits? checkin, checkintoo, rcheckin? rcheckin is heavily advised!

What I do to automate your workflow :

(here 'bitbucket' is the supposed name of your remote bitbucket repository)

=> in your master branch :

//Do your job & commit with git & ...
//rebase your work on TFS work
git tfs pull -r
//rcheckin with git-tfs
git tfs rcheckin
//commit in bitbucket repo
git push bitbucket master

=> in your 'NewBranchName' branch :

//Do your job & commit with git & ...
//rebase your work on TFS work
git tfs pull -r -i NewBranchName
//rcheckin with git-tfs
git tfs rcheckin -i NewBranchName
//commit in bitbucket repo
git push bitbucket NewBranchName

PS2 : Perhaps, you should have to stash your modifications if you have uncommited changes in your working directory before doing pull -r and rcheckin...

EDIT : You edit, I edit ;)

Before, I suppose that you have defined a remote for your bitbucket repository :

git remote add bitbucket https://bitbucket.org/yout_login/your_project.git

You have just to :

//checkout your branch
git checkout NewBranchName
//fetch the TFS changesets and merge your branch into
git tfs pull -r -i NewBranchName
//push your commit on bitbucket
git push bitbucket NewBranchName

And to explain a little what you are doing (and not understand totally :( )...

With "git tfs fetch --all", you are fetching the TFS changeset of all the branches but not merging (or rebasing) with your local branch. So they doesn't appear in your local branch. You could see the DAG with the command to better understand :

git log --oneline --graph --decorate

The 'git tfs pull' given above merge the fetched commit with your branch so that will be good!

"git status" tells me there is nothing to commit

This command show you the files that are modified in the working directory. So, that's normal that you see no changes. That does say that your commit was not pulled!

And when I try to push this changeset into BitBucket, git tells me there is nothing to commit.

You should have! Are you sure to have define your remote toward your bitbucket repository? (see above) Which command you use? What git tell you?

Philippe
  • 28,207
  • 6
  • 54
  • 78
  • I think I've not described my problem. I have edited my question to with more info. Basically, I am trying to duplicate the TFS repository in BitBucket. I don't want to add anything from BitBucket into TFS – Simply Ged Apr 23 '13 at 17:11
  • See my edit. I understand better your workflow (but not all your problems :( ). Hope it will help! – Philippe Apr 23 '13 at 22:15
0

The git tfs fetch command doesn't update your local git repository, that's why you should do git merge after that.

To do the same in one command simply do pull from TFS remotes

git tfs pull -r

This should update local git repository with all new updates from TFS server

At this point you just need to push updates to git server:

git push -u origin --all