0

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.

enter image description here

enter image description here

enter image description here

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..

enter image description here

Any advise would be much appreciated.. Thanks!

asked Jun 5, 2025 at 8:28
3
  • 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. Commented 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 Studio Commented Jun 5, 2025 at 8:49
  • 1
    Visual 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. Commented Jun 5, 2025 at 8:50

2 Answers 2

0

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

answered Jun 5, 2025 at 8:36
Sign up to request clarification or add additional context in comments.

1 Comment

I just restarted my computer and was not able to connect to the repo anymore.. However I have cloned the initial git repo and was able to commit the first changes.. Should the problem occur again I will try to follow your steps. Thanks
0

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.

answered Jun 5, 2025 at 8:54

3 Comments

I just ran into the same problem.. It seems that not all commints going to the same location. I can see a portion of the repo in the project folder and another repo in C:/Users/[...]/source/repos folder. But when I load this repo it doesn't contain any files with the code.. However the initial repo in the project folder doesn't react at all. I cannot load it manually nor something happens if I select it in Visual Studio.. I've never experienced anything similar in VSCode..
Run this in your terminal while inside your project folder 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
git re-parse --show-toplevel returns the path of the actual project. I have deleted the unintended repo and restarted Visual Studio and the .sln. Now I only see one repo but I cannot select it. Either if I chose it in the lower taskbar nor in the upper navigation bar. It does not get selected

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.