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 short cut 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 was 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.
2
Answers
git branch --delete master
likely failed because you currently have themaster
branch checked out, and git will not allow you to delete the branch you are currently working from.From your question however, I assume you didn’t want to delete the branch but rather remove git from the local repository itself.
If, as you described, you have a new remote (GitHub) repository created, you don’t have to "delete" or "remove" anything, you can simply change the remote origin of the your local git repository:
git remote set-url origin <url to your remote (GitHub) repository>
From there pushing the local repository to
origin
will push to the new remote repository you’ve set up:(*note: depending on the state of your new remote repository, you may have to address merge conflicts or
git push --force origin master
.)If you do want to delete git from the local repository: Everything related to git is contained in the .git directory of your local repositry. If you simply
rm -rf .git/
from the root directory of your local repository, it will no longer be seen as a git repository. If you do this via the command line or otherwise, VS Code will automatically recognize that the directory is no longer a git repository.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 itoriginal
).If
copy
is supposed to be a brand new project, that starts with the current (renamed) content oforiginal
and that should not keep track oforiginal
‘s history, then you need to delete the hidden folder.git
fromcopy
‘s working directory, initialize a new repository withgit init
, stage and commit the current content, create a new repository on GitHub forcopy
, add the new remote tocopy
withgit add remote origin <copy_url>
, and finally push to the remote.Instead, if
copy
is supposed to be a parallel project oforiginal
and retainoriginal
‘s history, then you could create a fork. To do that, go tooriginal
‘s repository on GitHub, click on thefork
arrow, selectCreate 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 affectoriginal
, unless a PR fromcopy
tooriginal
is performed.Lastly,
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 with all its history, you need to delete the hidden
.git
folder 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.