Faygris
Faygris

Reputation: 325

Push an existing project into a new Azure DevOps repository in Visual Studio 2022

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:

enter image description here

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

Answers (4)

Scott K
Scott K

Reputation: 71

The easiest and "safest" way I have found to do this.

  1. Rename your local solution directory to something else (Project to ProjectV2)
  2. Clone the repository from AzDO (Creating new Project directory)
  3. Copy the files from ProjectV2 back into Project.
  4. Check it in.

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

Holm76
Holm76

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

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30362

Please follow below steps to add an existing project into a new Azure DevOps Git repo in VS 2022:

  1. View -> Team Explorer enter image description here

  2. Manage Connections -> Connect to a project enter image description here

  3. Add an Azure DevOps server or online service account -> Select the project and your new repo -> Clone enter image description here

  4. After that, go to Solution Explorer -> Select the root folder and right-click -> Select "Open Folder in File Explorer".

  • enter image description here
  1. 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. enter image description here

  2. Push the changes to the remote repo, then check the repo in Azure DevOps. enter image description here enter image description here

Upvotes: 4

DavidCox88
DavidCox88

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

Related Questions