Finding Git Repositories with PowerShell

As part of my ongoing improvement process this year I am starting to use Git much more. Yesterday I posted an article with my PowerShell script to create a new project folder which includes creating a Git repository. My challenge has been that I don’t always remember what I have set up with Git and what I have not. So I put together a little PowerShell function to identify folders with Git repositories.

The function, Find-GitRepository, takes a top-level path as a parameter. The function then searches all sub folders searching for hidden directories called .git. For each directory, the function creates a custom object that includes the path and details about the Git repository. To get those values the command jumps to each folder where I parse the results of git branch and git log.

find git repositories with PowerShell

There’s probably a bit more information I could pull with Git but for now this seems to be enough for me. You can find the function as a gist in my Github repository.

As with my previous script, I assume you have the git command line tools in your path.  If you use Git I hope you’ll try it out and let me know what you think.