ugit (Updated Git) is a powerful PowerShell module for git that lets you: output git as objects, automate multiple repos, and extend git.
ugit is a PowerShell module that gives you an updated git. You can use the object pipeline to pipe folders or files into git.
If you're using one of a number of supported commands, ugit will return your git output as objects.
This enables a lot of interesting scenarios, giving you and updated way to work with git.
# Install ugit from the PowerShell Gallery
Install-Module ugit -Scope CurrentUser
# Then import it.
Import-Module ugit -Force -PassThru
# Once you've imported ugit, just run git commands normally.
# If ugit has an extension for the command, it will output as an object.
# These objects can be formatted by PowerShell
git log -n 5
# To get a sense of what you can do, pipe a given git command into Get-Member.
git log -n 5 |
Get-Member
ugit only has a few commands:
After you've imported ugit, Use-Git is what will be called when you run "git".
This happens because Use-Git is aliased to "git", and aliases are resolved first in PowerShell.
Use-Git assumes all positional parameters are arguments to Git, and passes them on directly.
This works in almost every scenario, except with some single character git options. You can pass these in quotes.
When Use-Git outputs, it sets $global:LastGitOutput and then pipes to Out-Git.
Out-Git will attempt to take git output and return it as a useful object.
This object can then be extended and formatted by PowerShell's Extended Type System.
Out-Git accomplishes this with several extensions. You can list extensions with Get-UGitExtension:
Get-UGitExtension enables any file beneath ugit (or a module that tags ugit) named *.ugit.extension.ps1 to be treated as an extension.
In ugit, extensions signal that they apply to a given git command by adding a [ValidatePattern]
attribute to the command.
If this pattern matches the given git command, the extension will run.
Get-UGitExtension is built using Piecemeal
ugit comes packed with many examples. You might want to try giving some of these a try.
git blame ugit.psd1
git branch -Remote
git branch # Get a list of branches
git branch | # Get all branches
Where-Object -Not IsCurrentBranch | # where it is not the current branch
Where-Object BranchName -NotIn 'main', 'master' | # and the name is not either main or master
git branch -d # then attempt to delete the branch.
git checkout -b CreateNewBranch
git checkout main
git clone https://github.com/MDN/content.git # This is a big repo. Progress bars will be very welcome.
# If we don't check things out, cloning is faster.
git clone https://github.com/PowerShell/PowerShell -NoCheckout
# (of course, that's because we're not copying files, just history)
# We can also clone more quickly by only picking a certain number of commits
git clone https://github.com/Microsoft/vscode.git -Depth 1
# (of course, this will make the history lie to you,
# by saying everything was changed whenever anything was changed)
git clone https://github.com/StartAutomating/ugit.git
# Clone a large repo.
# When --progress is provided, Write-Progress will be called.
git clone https://github.com/Azure/azure-quickstart-templates --progress
git commit -Title "Fixing Something"
git commit -Title "Changing Stuff" -Trailers @{"Co-Authored-By"="SOMEONE ELSE <[email protected]>"}
git commit -m "Updating #123"
$committedMessage = git commit -m "Committting Stuff" # Whoops, this commit had a typo
$commitMessage.Amend("Committing stuff") # that's better
git config --list
git config --global --list
git config --list --local
git config --list --show-origin
git diff --name-only
git archive -o My.zip
git branch --format "{'ref':'%(refname:short)','parent':'%(parent)'}"
git branch --format "%(refname:short)|%(objectname)|%(parent)|%(committerdate:iso8601)|%(objecttype)"
git grep '-i' example # look for all examples in the repository
git help -a
git help --all
git init # Initialize the current directory as a repository
git log -CurrentBranch
# Get all logs
git log |
# until the first merged pull request
Where-Object -Not Merged
# Get a single log entry
git log -n 1 |
# and see what the log object can do.
Get-Member
# Get all logs
git log |
# Group them by the author
Group-Object GitUserEmail -NoElement |
# sort them by count
Sort-Object Count -Descending
# Get all logs
git log |
# Group them by day of week
Group-Object { $_.CommitDate.DayOfWeek } -NoElement
# Get all logs
git log |
# where there is a pull request number
Where-Object PullRequestNumber |
# pick out the PullRequestNumber and CommitDate
Select PullRequestNumber, CommitDate
git log --merges
git mv .\OldName.txt .\NewName.txt
git mv .\OldName.txt .\NewName.txt --verbose
git pull
git push
git reflog
git remote
git remote | git remote get-url
git remote | git remote show
git rm .\FileIDontCareAbout.txt
git shortlog # Get a shortlog
git shortlog --email # Get a shortlog with email information
git shortlog --summary # Get a shortlog summary
git shortlog --sumary --email # Get a shortlog summary, with email.
git sparse-checkout -FileFilters *.ps1,*.psm1
git stash list
git status
git status | Select-Object -ExpandProperty Untracked
git submodule
Most extensions handle output from a single git command.
A few extensions handle output from any number of git commands, depending on the arguments.
- Git.FileName
This applies to any git command that uses --name-only. It will attempt to return the name as a file, or as an object containing the name.
- Git.FileOutput
This applies to an git command that uses the -o flag. It will attempt to locate any output specified by -o and return it as a file or directory.
ugit also allows you to extend the input for git.
ugit is part of the core of GitLogger.
GitLogger uses ugit to turn logs into objects and then provides standardized metrics and a way to query your logs.