gitvisual-studiogithub

How can I remove a git and github repository connection to a solution in Visual Studio 2022?


First of all, I should explain the mess I have gotten myself into in order to explain this issue. (This was a windows form application with .Net Framework version 4.7.2.) I had the idea while thinking outside of the proverbial box, that a shortcut to a problem I was facing was to make a complete copy of an entire project's source code and rename the project a new name. All of the files with the previous project name were renamed to the name of the new project. Also, in all of the files, where this name appeared, was edited to be the name of the new project file.

Now, here is the problem, this created a kind of ghost git and GitHub repository. There seems to be a local repository, but on GitHub there was nothing. But when I tried to create a new GitHub repository online, the files from the old project seemed to be referenced.

I closed the Visual Studio IDE and went to the command line to try to delete the local git repository with

git branch --delete master

but it returned with

error: cannot delete branch 'master' used by worktree at 'C:/source/DHS-Solution'

So I think this means I need to find a way to disconnect from the git and GitHub through the IDE. Please advise.


Solution

  • It seems like you were trying to create a whole new independent project (I will call it copy) based off one of your other projects (I will call it original).

    If copy is supposed to be a brand-new project with a new history that starts with the current (renamed) content of original, then you need to delete the hidden folder .git from copy's working directory, initialize a new repository with git init, stage and commit the current content, create a new repository on GitHub for copy, add the new remote to copy with git add remote origin <copy_url>, and finally push to the remote.

    Instead, if copy is supposed to be a parallel project of original and retain original's history, then you could create a fork. To do that, go to original's repository on GitHub, click on the fork arrow, select Create a new fork, and clone the newly created repo. The cloned repository (copy) will already point to the new remote, and all the changes committed to it won't affect original, unless a PR from copy to original is performed.

    Lastly,

    went to the command line to try to delete the local git repository with git branch --delete master

    a branch represents only a line of development. It is not your repository, even if this is your main line of development. If you want to delete a repository along with its history of changes, you need to delete the hidden folder .git in the project's working directory.

    Also, you cannot delete your currently checked out branch, you need to select a different branch to delete the current one. Furthermore, you can only delete branches whose changes are included in the current branch, unless you perform a forced deletion.