43

Microsoft now has support for Git repositories on their Team Foundation Service. I have an account on Team Foundation Service, and I'd like to push my existing Git repository to a project there.

Whenever I try to do searches, I keep finding things like TFS-GIT, or GIT-TF. I'm pretty sure I don't want those, as I think those change to the Team Foundation Server model for code repositories, and that's not what I want.

Specifically, I have an existing Git repository that I want to push to TFService.

McKay
  • 12,334
  • 7
  • 53
  • 76
  • possible duplicate of [how to import Git project to TFS Cloud](http://stackoverflow.com/questions/14630161/how-to-import-git-project-to-tfs-cloud) – Edward Thomson Feb 28 '13 at 16:31
  • There is also http://stackoverflow.com/questions/14711796/publish-local-git-repository-to-team-foundation-service/14740846#14740846 – SteveC May 28 '13 at 14:39

6 Answers6

31

Okay, I was apparently overcomplicating this. Here's what I did.

  1. Created a new project in TFService
  2. Connected to that project in Visual Studio
  3. Cloned that project in Visual Studio
  4. git pull c:\source\oldGitProject

That was it, it pulled all of the changes from the old location, and I could push that up to TFService easily.

McKay
  • 12,334
  • 7
  • 53
  • 76
  • 1
    That can work too, instead of my `git push --mirror` approach of my answer. +1 – VonC Mar 03 '13 at 00:10
  • Yeah, but this way, I didn't have to set up a remote push location, and I didn't have to get any command line authentication working in TFS in the cloud. – McKay Mar 03 '13 at 00:52
  • Sounds definitively better, then :) – VonC Mar 03 '13 at 00:54
  • I was going crazy with this task... Tried a lot of paths and now it makes sense. THANK YOU! :D – Leniel Maccaferri Apr 26 '13 at 03:31
  • I discovered by accident that even this can be further simplified to 3 simple steps. i.e. you dont need to pull the existing repo or clone the new empty project. See my answer for details. Luvin this git command line. – rism Jun 25 '14 at 10:15
23

"how do I push my existing git repository to TFService?"

Once you have declared a git repo on tfs.visualstudio.com (see below), add that git repo url to the remotes of your own local repo:

cd /path/to/local/repo
git remote add tfs url://tfs/git/repo
git push --mirror tfs

That will be enough to push the full history of your local repo back to that new upstream repo on TFS.

Again, the idea is to create a new empty repo on the upstream side (TFS), and to push your local repo to it.


(Original answer)

If I understand Scott Hanselman's blog post about it:

This Git support will require VS2012.2 (currently in preview) so you'll need to install that first, then get the VSIX. You'll be able to update both when VS2012.2 is released, and the Git VSIX will continue to update automatically via the VS Gallery.

It's a full source code provider for VS so you can use it to do most anything without leaving VS, or you can hang out at the command line and use it for a visual reminder as to the state of your repository.

For teams, you can go up to http://tfs.visualstudio.com and sign up for a account and get 5 users for free. You can choose either Git or Team Foundation Version Control (TFVC) as the source provider and use all the Team Foundation agile, scrum or other templates for your ALM tools

The registration process for a Git project is illustrated here, again pointing out that you need the “community technology preview” of the Git VSIX on top of a “community technology preview” of VS 2012 Update 2 (VS2012.2).

Git project in TFS

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    The question I have isn't "how do I start using git for a new project in TFService?", but "how do I push my existing git repository to TFService?" – McKay Feb 28 '13 at 15:53
  • I'll give that a shot. the --mirror seems like it might be what I want. – McKay Feb 28 '13 at 16:24
  • @McKay yes, it will push all your local git repo refs: all branches and all tags. – VonC Feb 28 '13 at 16:26
  • Yeah, your suggestion seems more promising than the possible solution I mentioned in my answer. I'll give yours a shot first (tonight). – McKay Feb 28 '13 at 16:27
  • This didn't work because of authentication issues? it might be because there's an "@" in my username for TFService? – McKay Mar 02 '13 at 04:42
  • @McKay If there is a '`@`' in your username, then try '`\100`' (as in http://askubuntu.com/q/80269/5470) – VonC Mar 02 '13 at 09:06
  • After following this i am getting: `fatal: https://yourname.visualstudio.com/DefaultCollection/ProjectName/info/refs not found: did you run git update-server-info on the server?` – Komengem Apr 26 '13 at 19:35
  • @KomengeMwandila that might be enough for a new question (with a reference back to this question) – VonC Apr 26 '13 at 19:36
  • @VonC I asked at http://stackoverflow.com/questions/16232683/team-foundation-service-fatal-when-git-push – Komengem Apr 26 '13 at 19:42
10

Some good answers above, but I found this even easier.

  • Create the local Git repository. (Or in my case, I converted my SVN repository to Git.)
  • Go to visualstudio.com and create the new project, specifying Git as the source control.
  • Click on the 'Code' menu option in the new project in VisualStudio.com.
  • The screen will show the exact Git command to push an existing repository, including the URL for your unique repository. All you have to do is copy and paste that command into your Git command prompt.

    git clone <repository url>

TimeTrap
  • 1,142
  • 1
  • 14
  • 18
Rick Arthur
  • 2,410
  • 21
  • 15
  • "copy and paste into your git command prompt" isn't enough information to satisfy the answer. What command do you use at said command prompt? – McKay Jan 07 '14 at 14:15
  • I updated to try and make it more specific. You copy and paste the Git command that is on the screen. – Rick Arthur Jan 08 '14 at 14:46
  • Oh, that sounds like they've made some changes since the version I was using at the time. I'll take a look at this. – McKay Jan 08 '14 at 16:39
  • You are correct. This is by far the easiest of the answers given. Thanks. – David Culp Jan 11 '16 at 11:45
5

All we need do is change the server target url of the existing local solution/repo.

So:

  1. In the cloud (TFService), create a new project and get it's url.
  2. On your local machine, open the existing solution/repo in Visual Studio and in the Package Management Console (PMC) run the following command

    git remote set-url origin https://new.url.here

  3. Using View>Team Explorer>Unsynched Commits push the existing solution / repo to the new project.

This will push the local repo, including all previous commits, to the new TFS project in the cloud.

Git command line FTW.

All this doing is updating the [url origin] attribute in the config file found in the .git folder, so you could just use notepad if you wanted to open and edit this file. IMHO this command is cleaner because you don't run the risk of accidentally editing some other setting nor do you have to leave VS.

Note: If the option to Push in step: 3 is disabled then you may have to perform another local commit in order to "dirty" the head of your source tree and thus enable the push command. Tho I'm sure there would be another git command to do this as well.

rism
  • 11,932
  • 16
  • 76
  • 116
1

One of the blogs I found this morning linked this document:

http://blogs.msdn.com/b/visualstudioalm/archive/2013/02/06/set-up-connect-and-publish-using-visual-studio-with-git.aspx#publish-tfs

(now archived at https://web.archive.org/web/20130316091444/http://blogs.msdn.com/b/visualstudioalm/archive/2013/02/06/set-up-connect-and-publish-using-visual-studio-with-git.aspx )

They appear to have an internal command called publish (which might be using the --mirror command that @VonC mentioned?)

I'm not sure if this works yet either.

McKay
  • 12,334
  • 7
  • 53
  • 76
  • "Publish" will work for a local git repo already linked to a tfs git repo. My solution is for the *initial* publication an *existing* git repo to tfs. After that, all got operations can be done through the GUI mentioned in that blog post, including the "Publish" command. +1 though for finding that blog post. – VonC Feb 28 '13 at 16:31
  • Yes, this is helpful, but doesn‘t work to push a Lola to the cloud. – McKay Mar 02 '13 at 04:27
  • 1
    The above link is broken, but here is a link from the internet archive: https://web.archive.org/web/20130316091444/http://blogs.msdn.com/b/visualstudioalm/archive/2013/02/06/set-up-connect-and-publish-using-visual-studio-with-git.aspx – Hermann.Gruber Jul 13 '22 at 08:10
1

Ran into this problem today. VonC's answer, adding TFS as a remote and using git push --mirror tfs, worked for me. However, it might be beneficial to mention some additional things about this.

  1. After the push, Visual Studio is still unable to identify that this local repo is connected to the Team Foundation Service in any way. So, you'll still need to select "Connect to Team Project..." and do a 'clone' using the interface. The repo from TFS will be cloned, with everything to just pushed. After this you'll be connected to TFS, and should be able to work normally in the clone.

  2. Using '--mirror' will push all local references, potentially including some local branches that you don't really want to have in the central repo. If this is the case, after pushing with '--mirror', you should use git push tfs :<branchname> to delete a branch from TFS in order to avoid other people later pulling your local branches.

  3. Alternatively, instead of '--mirror', it should be possible to just push the desired refs into the TFS repo, just like you would any other git repo: git push tfs <refspec>. Since the TFS repo is still empty at this stage, a bunch of branch names one after the other should be enough as a <refspec>. If using this method you could also use use git push -u, which will also make the branches you push into the empty repo tracking branches.

EDIT: As mentioned in Edward Thomson's comment, cloning from TFS should be unnecessary if your original repo is configured to track a branch from the TFS remote. So git push -u <refspec> should both push the repo to the empty TFS repo, and also allow the IDE to recognize the original local repo because it sets up tracking.

avivr
  • 1,393
  • 15
  • 28
  • `push --mirror` doesn't set up tracking branches with the remote (intentionally.) You needn't re-clone your repository, you only need to set up a tracking branch with the new remote in your `.git/config`. – Edward Thomson Mar 01 '13 at 15:55
  • I was referring to the IDE not recognizing the original local repo as cloned from the TFS repo, even after doing what VonC suggested. – avivr Mar 01 '13 at 17:55
  • Right -- once you've set up the tracking branch in your `.git/config`, Visual Studio should read that data and then able to identify your remotes. – Edward Thomson Mar 01 '13 at 20:45
  • Thanks for the info, wish that was documented somewhere. So if you're right, pushing the original repo to TFS with '-u' should produce all the desired effects - TFS repo would receive the data, and the IDE would recognize the repo since tracking branches would be set up. – avivr Mar 01 '13 at 23:21
  • We did this for consistency with core git -- but I think this is something that we'll be revisiting in a future release. Thanks for the input. – Edward Thomson Mar 02 '13 at 00:14