Skip to content

Instantly share code, notes, and snippets.

@reschex
Last active November 21, 2023 13:47
Show Gist options
  • Save reschex/ebd872b5df60a8d79129e1561da288c8 to your computer and use it in GitHub Desktop.
Save reschex/ebd872b5df60a8d79129e1561da288c8 to your computer and use it in GitHub Desktop.
powershell profile git functions
# git get
function gg {
git pull
}
function Get-GitPrompt {
$branch = git branch --show-current 2>$null
switch ($branch) {
"main" { $COLOUR = $RED }
"master" { $COLOUR = $RED }
"develop" { $COLOUR = $GREEN }
Default { $COLOUR = $YELLOW }
}
$prompt = "[" + $COLOUR + $($branch) + $END + "] "
return $branch ? $prompt : ''
}
# git branch - start a new feature
function New-GitBranch {
param (
[Parameter(Mandatory = $true)]
[string]$branch
)
$currentBranch = Get-GitPrompt
Write-Host $BOLD$MAGENTA"[ Git Branch ]"$END
Write-Host $BLUE"On branch:"$END $currentBranch
if ($currentBranch) {
Write-Host $YELLOW"> Pull"$END
git pull
Write-Host $YELLOW"> Creating new branch"$END
git checkout -b $branch
Write-Host $YELLOW"> Publishing new branch"$END
git push -u origin $branch
}
}
# Remove-Alias gb -Force
New-Alias gb New-GitBranch -Force # -option 'Constant','AllScope'
# git lazy - add all files, commit all files and publish all changes
function New-GitCommit {
Write-Host $BOLD$MAGENTA"[ Git Lazy ]"$END
$branch = Get-GitPrompt
if ($branch) {
Write-Host $BLUE"On branch:"$END $branch
Write-Host $YELLOW"> Pull"$END
git pull
Write-Host $YELLOW"> Adding files"$END
git status -s
git add --all
$commitMsg = $args
Write-Host $YELLOW"> Commit" $commitMsg$END
git commit --all -m "$commitMsg"
Write-Host $YELLOW"> Push"$END
git push
} else {
Write-Host $RED"> Not in a git repo"$END
}
}
# Remove-Alias gl -Force
New-Alias gl New-GitCommit -Force # -option 'Constant','AllScope'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment