Git to TFS Source Control Migration
Asked Answered
L

5

16

I'd like to see how TFS will work for my command. So I'd like to move our current GIT repository to TFS database. We've used GIT for it's prevailed branching support so I'd like to use TFS 2010 to address that issue.

Now question is. How do I export our GIT repo to TFS. Obviously it's some kind of script. Does have anyone done that? Any suggestions?

Thank you.

Lysenkoism answered 31/12, 2009 at 0:13 Comment(4)
Why the hell would anyone move from git to tfs?Winther
Two words: better tooling. I know that git have a lot of hype. And Mr. Torwalds himself wrote a batch of it it, but interacting with this thing SUCKS. I've used it for a 19 month now, I've introduced it to the team and I do not think of it as a silver bullet. All of the UI tools are lame. Command-line interface is verbose. I have the set of scripts to support my workflow, but it's not a solution I proud of. Plus TFS is more than source control. It's a complex solution: bug tracker, build system, VS integration, SP site for none-developers to watch the process and submit bugs, etc.Lysenkoism
Git extensions code.google.com/p/gitextensions is rapidly making Artem's comment obsolete. A much nicer UI than the bundled UIs.Homograft
If I have the choice between Git, SVN and TFS my preference would be: 1. SVN, 2. TFS, 3. GitClarindaclarine
F
11

Microsoft have now released their own GIT <--> TFS extension for GIT: GIT-TF

This allows pulling a new GIT repository from TFS or configuring to allow GIT to TFS pushes, which is what you want to do:

(from the documentation)

For a team working with an existing Git repo, a developer sharing changes to TFS using Git-TF would use the following workflow.

# Configure the existing repo's relationship with TFS
git tf configure http://myserver:8080/tfs $/TeamProjectA/Main

# Fetch the latest changes from TFS and merge those 
# changes with the local changes.
# Note, merging is important when working in a team configuration. 
# See "Rebase vs. Merge" below.
git tf pull

git commit -a -m "merge commit"

# Check in the merge commit as a single TFS changeset
git tf checkin

# Push the merge commit to the origin
git push

In addition, the preexisting open-source GIT-TFS solution can be used (from Windows only, Microsoft's solution uses Java and is cross-platform), described in an answer to Git to TFS 2008 one way migration (with history)

Finis answered 15/8, 2012 at 9:32 Comment(1)
This solution will only work whithout branches. If you have branches, a better solution will be to use TFS2013(Git)Loquat
L
5

I created a quick batch file, but you need to have Team Foundation Power Tools (tfpt.exe) in your path and For (a command line loop command)

Visual Studio Command line to your desired git folder and run the following.

git log --pretty="'%%H',%%ci - %%s" --reverse > commits

tf workspace temp /new /s:http://{TfsInstance} /i
tf workfold /map %2 . /workspace:temp

FOR /F "tokens=1* delims=','" %%a IN (commits) DO git checkout %%a && tfpt online /recursive /exclude:.git*,commits,*.obj,*.exe,_ReSharper*,obj,debug,*.user,*.suo,Bin /adds /deletes /i && tf checkin /author:"{AuthorName}" /comment:"%%b" /i

tf workspace temp /delete /i
  1. First it creates a commits file with all the commit information in reverse order (earliest first).
  2. Then it creates a Team Foundation workspace... (be sure to replace {TtsInstance} with your TFS URI.
  3. Then it creates a temporary folder in the workspace.
  4. Then it loops through each line in the commits file, does a checkout from git, uses TFPT to check in the current files (again be sure to replace {AuthorName} with your author name) the comment will include the timestamp from git (unfortunately you can't change checkin time without changing the TFS server's time and I would recommend against that) and the original author's name.

This worked okay, but branches won't be perserved. I didn't take the time to figure out branching since it wasn't a big enough factor for the job at the time.

Hopefully this can save someone some time!

Lorikeet answered 7/7, 2010 at 18:29 Comment(1)
I added Thumbs.db to the tfpt exclude list. I had deleted it from the git history because it was accidentally added before I had included a .gitignore file, and was receiving errors when I ran the .bat file.Concede
L
2

Set up a SVNBridge to TFS and then use git-svn clone.

Lorikeet answered 15/4, 2010 at 16:44 Comment(2)
It's git svn update but you are right. I've done exactly this thing.Lysenkoism
I don't see a command git svn update in the Git docs anymore, although I did find git svn dcommit, which "Commit[s] each diff from the current branch directly to the SVN repository, and then rebase[s] or reset[s] (depending on whether or not there is a diff between SVN and head). This will create a revision in SVN for each commit in git." So if this supposed to be the same thing?Spectrophotometer
I
0

You may be able to export git to svn, and use CS Converter to go from svn to TFVS. Note - CS Converter has been discontinued, but it looks like you can still download it.

Iceberg answered 31/12, 2009 at 0:40 Comment(0)
A
-1

This is an old question, and maybe no one is looking for this anymore, but it is a lot easier now.

  1. Create a Team Project in TFS with Git as the source code control

  2. Grab the Git url for the project. It will look something like ... https://YOURPROJECTS.visualstudio.com/DefaultCollection/_git/PROJECTNAME

  3. Drop into the command like and execute.

    git remote add origin https://YOURPROJECTS.visualstudio.com/DefaultCollection/_git/PROJECTNAME

    git push -u origin --all

Should be all you need.

Aerometry answered 27/11, 2016 at 17:13 Comment(1)
Not truly helpful, as when using TFS-hosted GIT, you don't get the full set of controls that you would have at your disposal as you would with a full TFS-managed project.Gentility

© 2022 - 2024 — McMap. All rights reserved.