Reputation: 325
I have an existing Visual Studio project with existing code
and a newly created Azure DevOps (git) project with an empty repository.
Now from Visual Studio 2022 I want to push my project into the DevOps repository.
This should be a very common problem, I guess.
However, when I use "Create Git Repository", it won't let me create the repository with the same name, since it already exists, because DevOps automatically creates a repository with the same name for a new project:
So I don't really need to create a new repository, but just connect to the existing one, so I can push the project there. But I haven't found a good way to do so.
My workaround so far was:
- Create the new DevOps project "MyApp"
- Create a second repository "Dummy" there, because there must be at least one
- Delete the "MyApp" repository
- Create a new "MyApp" repository from Visual Studio
- Delete the "Dummy" repository
That works, but it's obviously stupid. There should be a straightforward, obvious way to do it.
I'm really confused I couldn't find a good answer online, as I believe this must be the second most common use case (after creating both a new DevOps project and a new VS project at the same time). Maybe I'm just terribly bad at googling.
Upvotes: 7
Views: 18268
Reputation: 71
The easiest and "safest" way I have found to do this.
The main advantage is that you have a backup of your code should something go wrong. Probably slightly more steps than you wanted but gives you lots of control.
Upvotes: 2
Reputation: 306
You properly already have this worked out but this is an issue with VS 2022. This worked in 2017 and 2019. You could create a new project with an initial repository with those editions but not with 2022.
The solution is to manually create your project on DevOps then rename default repository and then add your 'new' repository to that project from Visual Studio 2022.
I have reported this as a bug to the Visual Studio team over ½ a year ago but they have done nothing about it so far.
Sometimes I install a 2019 or 2017 and add new projects with those versions and then move back to 2022.
Upvotes: 1
Reputation: 30362
Please follow below steps to add an existing project into a new Azure DevOps Git repo in VS 2022:
Add an Azure DevOps server or online service account -> Select the project and your new repo -> Clone
After that, go to Solution Explorer -> Select the root folder and right-click -> Select "Open Folder in File Explorer".
Open your local existing project folder, copy the solution directory to the folder opened in step 4, then go to the Git changes explorer, check the changes and Commit all. If you cannot see the Git explorer, then please open it from View -> Git Changes.
Push the changes to the remote repo, then check the repo in Azure DevOps.
Upvotes: 4
Reputation: 1018
In the image, under Other you have Existing Remote. You can use this and add the url to the repo that was created by default
Upvotes: 3