Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Finding Git Repositories with PowerShell

Posted on May 18, 2016

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.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

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.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d