2

I store my open source projects usually on Github which works easily with VS. But once in a while I want to store a project only I use on Azure DevOps. Since I do this only once every few years and VS has changed its GIT GUI greatly, I can't figure out how to make it work.

Of course, I can use Add to Source Control and in the Create a Git repository Window Azure Dev Ops. But here I get stuck:

enter image description here

This window insist that I am using an already existing project on Azur DevOps. However, I want this new solution to be its own project on Azur DevOps. So I logged in to visualstudio.com and created a new project:

enter image description here

When I now open Add to Source Control again, I can indeed chose that new project, but now I get an error message:

enter image description here

The error message says: A repository with this name exists already :-(

Question:

What do I need to do to add a new VS solution to Azure DevOps and I want the Azure DevOps Project and Repository each have the same name as the VS solution.

What I tried so far

I tried to delete the repository on Azure DevOps:

enter image description here

I when I clicked on Delete, nothing happened, the repository was still there.

I then tried to rename the repository:

enter image description here

When I clicked on rename, it seemed that rename got executed.

I then opened Add to Source Control again, and this time there was no error:

enter image description here

So I clicked Create and Push.

Which seemed to work. I then deleted the renamed Repository on Azure DevOps, which seemed to work too.

However, I cannot imagine that such a basic operation of adding a new solution to Azure DevOps is so complicated. Is there any easier way ? Will I run into problem later because of my strange approach ?

Please Note: I have searched for similar question on SO and there are many. But please note that this question is about VS2022. Any question older than half a year cannot be about VS2022. However, the git functionality has changed a lot between different VS versions.

Peter Huber
  • 3,052
  • 2
  • 30
  • 42
  • Is the problem simply that when you create the project in AzDO that it also creates a default repo with the same name? Seems like if it didn't also create the repo you would have been fine. Maybe there's a setting when you create the project? (I don't have time to check at the moment). – TTT Aug 20 '22 at 15:47
  • Also, you don't have to "create" the repo from your machine. If there is already a (nearly) blank repo on AzDO you could simply clone it and then update it however you'd like and push it back up. – TTT Aug 20 '22 at 15:49
  • Sorry, my git knowledge is not that good. For this question I made it simple by using a new VS solution, but in reality I have often programmed already for a week or so when I decide to add it to AzDO, meaning my VS solution is not empty. Is it really possible that I can clone an empty AzDO repo over my existing VS solution ? I always thought a clone requires that nothing is on my PC and the cloned repo on my PC will be exactly the same as the repo on AzDO ? – Peter Huber Aug 21 '22 at 03:12
  • There is a simple workaround for creating a repo into a different directory and then moving it. Also, I just confirmed your issue and posted an answer with some options. – TTT Aug 21 '22 at 06:35

1 Answers1

1

I just confirmed what you witnessed, and I think I understand what's happening. When you create a new Project in Azure DevOps (AzDO), and select the Git option, it also creates an empty repo with the same name. Every AzDO project must have at least one repo. Therefore you cannot delete the default repo until at least one more repo exists, otherwise you will get this error:

TFS.WebApi.Exception: There must always be at least one repository per Team Project.

So what can you do if you want to create a repo with the same name as the new project? Here are a few options:

  1. Don't name your project exactly what you want your repo to be called. You can then delete the default repo later if desired after you've added a new one.
  2. Do exactly what you did: rename the default repo, upload your repo with the original name, and then delete the renamed repo.
  3. You can clone the default repo into another directory, and then move the .git folder into your actual code directory.
  4. You can create a repo in your code folder and then add the remote afterwards.

I think in your shoes I'd probably go with number 3 since it's the fastest, though, it does require using the Git command line to clone and provide the extra argument for the temp folder location.

Sanity Tip: In a comment you mentioned:

... in reality I have often programmed already for a week or so when I decide to add it to AzDO...

If you're still learning Git, before adding your existing codebase to a Git repo, I recommend making a backup copy of your code. There are far too many horror stories on this site about people who accidentally instructed Git to blow away their files, and Git did it. Once you commit your work you should be able to get it back, but sometimes people learning Git don't know that, and they issue commands that delete files before they ever committed. Or, they might delete the repo that contained their work.

TTT
  • 22,611
  • 8
  • 63
  • 69
  • 1
    I am using Git since years :-) But I avoid it as much as possible and let VS emit the needed Git commands. What I cannot believe is that such a basic operation like adding a new VS solution to AzDO is SO complicated. It really shouldn't be, so I wonder if I did something wrong. Thanks for confirming that there seems to be no easy way. – Peter Huber Aug 21 '22 at 13:34
  • I'm annoyed the same error message still appears even if a TFVC repository is present, and just trying to remove the GIT repository. Microsoft has crucified TFVC users over the years in the pursuit of git and they still can't spell 'repository' properly ... for some reason they keep calling it 'repo' in the interface. Bitter? Yes. Microsoft, if there are two repositories, one is TFVC the other is GIT, then removing the GIT one should not give the error 'There must always be at least one repository per Team Project.' It's simple math. – Sid James Oct 27 '22 at 18:02