Skip to content

Instantly share code, notes, and snippets.

@sannae
Last active August 13, 2021 13:28
Show Gist options
  • Save sannae/cc21a56d261fbcc58d8e6bd63874976a to your computer and use it in GitHub Desktop.
Save sannae/cc21a56d261fbcc58d8e6bd63874976a to your computer and use it in GitHub Desktop.
One-liner to add, commit and push to remote Git
function New-GitCommit {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]
[string]$CommitMessage
)
Write-Host "Git - Adding all changes..." -ForeGroundColor Green
git add --all
Write-Host "Git - Committing with provided message..." -ForeGroundColor Green
git commit -m $CommitMessage | Tee-Object -Variable GitCommit
Write-Host $GitCOmmit
if ( -Not ("nothing to commit, working tree clean" -in $GitCommit) ) {
Write-Host "Git - Pushing to remote origin..." -ForeGroundColor Green
git push
}
}
Set-Alias -Name "ngc" -Value "New-GitCommit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment