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:
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
When I now open Add to Source Control again, I can indeed chose that new project, but now I get an error message:
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:
I when I clicked on Delete, nothing happened, the repository was still there.
I then tried to rename the repository:
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:
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.
CodePudding user response:
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:
- 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.
- Do exactly what you did: rename the default repo, upload your repo with the original name, and then delete the renamed repo.
- You can clone the default repo into another directory, and then move the
.git
folder into your actual code directory. - 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.