Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a directory is a git repository in C#

I've started using LibGit2Sharp in my project and I have to admit its pretty awesome. I'm glad i didnt go the command line route with processinfo. But I have a question which I couldn't find an answer for in the wiki and could not find a test in the source code that had it. How can you check with LibGit2Sharp if a folder is a git repository?

like image 624
wendellmva Avatar asked Jun 15 '14 14:06

wendellmva


People also ask

What directory is git repository?

The default location that Git Bash starts in is typically the home directory (~) or /c/users/<Windows-user-account>/ on Windows OS. To determine the current directory, type pwd at the $ prompt. Change directory (cd) into the folder that you created for hosting the repository locally.

How do I find my git repository?

You typically obtain a Git repository in one of two ways: You can take a local directory that is currently not under version control, and turn it into a Git repository, or. You can clone an existing Git repository from elsewhere.

Is .git a folder or a file?

The . git folder contains all information that is necessary for the project and all information relating commits, remote repository address, etc. It also contains a log that stores the commit history.


1 Answers

You can call Repository.IsValid(path). The source code for Repository is here.

The path can be either to the .git folder or to the working directory.

like image 138
Matthew Strawbridge Avatar answered Oct 29 '22 10:10

Matthew Strawbridge