I'm currently working on a WPF project in Visual Studio. Therefore I have created a Git Repository in Visual Studio itself. I can see the repository in my Git Hub and as per Visual Studio I'm also connected. Previously I could see the master branch in the history.
However whenever I'm trying to Commit my change or create a new Branch now, I get the attached error message. I also noticed that I don't see the master branch in the Git history anymore.
I really have no idea where I can check for the problem.. The .Git folder exist but even after making it visible I cant see it in the Solution viewer..
Any advise would be much appreciated.. Thanks!
-
Does the repo have an initial commit? If not, have you tried to make the initial commit manually from command line? Also, your repo seems to be in a synchronized folder, which can cause issues.RedStoneMatt– RedStoneMatt2025年06月05日 08:37:56 +00:00Commented Jun 5, 2025 at 8:37
-
No I haven't done any commits since I initiated the repo except adding the .gitignore and .gitattribute after prompted by Visual StudioLeXXan– LeXXan2025年06月05日 08:49:38 +00:00Commented Jun 5, 2025 at 8:49
-
1Visual Studio usually makes an initial commit when you ask it to create a repo. Maybe it bugged and didn't do it, which confuses it when trying to commit now. Maybe try to make the initial commit by hand with the command line, then see if later commits work with VS or if it's still broken.RedStoneMatt– RedStoneMatt2025年06月05日 08:50:55 +00:00Commented Jun 5, 2025 at 8:50
2 Answers 2
Check the version of git on typing git -- version in terminal . once got git version then
Check if you're in a Detached HEAD state
Go to View > Git Repository.
If it says HEAD instead of a branch name, you are in a detached HEAD.
check if the branch was deleted or renamed remotely
Go to Git > Manage Branches in Visual Studio.
See if any branch is listed under Remotes/origin/.
If you see only main and not master, then maybe master was renamed to main on GitHub
1 Comment
You do have a .git folder in the root of your project (KanbanBoardApp), which confirms it's still a Git repository. Can you double check .git folder is there.
1. You can check git status
cd "C:\Users\<your-name>\Project Software Engineering\KanbanBoardApp"
git status
If git status fails with the same error: The .git folder might be corrupted.
2.Open the .git folder in File Explorer. It should contain files/folders like:
HEAD
Config
Objects/
refers/
If these are missing or unusually empty, the Git metadata might be damaged.
If Git is broken beyond repair:
Backup your project folder (copy everything except .git)
Delete the .git folder
Re-clone the repo from GitHub into a new folder
Copy your project files into the new repo folder
Commit and push again.
3 Comments
git rev-parse --show-toplevel This tells you the actual Git root directory. 1.Back up your project folder 2.Delete the unintended repo in C:\Users\...\source\repos\... (if it doesn't contain anything useful). 3.Open Visual Studio and choose "Open a Project or Solution", then open the .sln