Modules/git.ps1
Remove-Alias gc -Force -ErrorAction SilentlyContinue Remove-Alias gcb -Force -ErrorAction SilentlyContinue Remove-Alias gcm -Force -ErrorAction SilentlyContinue Remove-Alias gcs -Force -ErrorAction SilentlyContinue Remove-Alias gl -Force -ErrorAction SilentlyContinue Remove-Alias gm -Force -ErrorAction SilentlyContinue Remove-Alias gp -Force -ErrorAction SilentlyContinue Remove-Alias gpv -Force -ErrorAction SilentlyContinue function g { git $args } function ga { git add $args } function gaa { git add --all $args } function gre($fullPath) { git restore --staged $($fullPath ? $fullPath : '.') } function gb { git branch $args } function gba { git branch -a $args } function gbr { git branch --remote $args } function gbd() { git branch -D $args git push origin --delete $args } function gc { git commit -v $args } function gc! { git commit -v --amend $args } function gclone { git clone --recursive $args } function gclean { git clean -df $args } function gw { git switch $args } function gf { git fetch $args } function gfa { git fetch --all --prune $args } function gs() { git status -bs } function gg() { git log --color --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(dim white)<%an>%Creset' --abbrev-commit } function gpush([string] $branchName) { if($branchName -eq '') { $branchName = git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' if($branchName -eq $null) { $branchName = 'main'; } } Write-Host "pushing main branch that name is '$branchName'..." Invoke-Expression "git push origin HEAD:$branchName" } function gpull([string] $branchName) { if($branchName -eq '') { $branchName = git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' if($null -eq $branchName) { $branchName = 'main'; } } Write-Host "pulling main branch that name is '$branchName'..." Invoke-Expression "git pull origin $branchName --recurse-submodules" } function Get-GitRemotes() { git remote -v } function Set-GitRemoteURL([string] $remoteName = 'origin', [string] $url) { git remote set-url $remoteName $url; gfa } function Find-CommitMessage([string] $keyword, [string] $author) { if($keyword -eq '' -and $author -eq '') { Write-Error 'call with any parameter !' return } $command = "git log --color --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(dim white)<%an>%Creset' --abbrev-commit" if($keyword -ne '') { $command += " --grep '$keyword'" } if($author -ne '') { $command += " --author '$author'" } Invoke-Expression $command } function Find-ContentsOnGitHistory([string] $matches) { $revList = git rev-list --all $searched = $revList | %{ git grep --color --line-number $matches $_ } if($searched.length -eq 0) { Write-Host -ForegroundColor White 'nothing' return } echo $searched[0..100] } function Get-GitConfig { git config --list $args } function Set-GitConfig([string] $name, [string] $email, [boolean] $isGlobal) { git config --$($isGlobal ? 'global' : 'local') user.name "$name" git config --$($isGlobal ? 'global' : 'local') user.email "$email" } |