Skip to content

add gswm and gswd command #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
| `gsts` | `git stash show --text $args` |
| `gsu` | `git submodule update $args` |
| `gsw` | `git switch $args` |
| `gswm` | Script to switch to main branch. |
| `gswd` | Script to switch to develop branch. |
| `gts` | `git tag -s $args` |
| `gunignore`| `git update-index --no-assume-unchanged $args` |
| `gunwip`| Script to remove a WIP commit. |
Expand Down
8 changes: 8 additions & 0 deletions src/aliases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ function gsu {
function gsw {
git switch $args
}
function gswm {
$MainBranch = Get-Git-MainBranch
git switch $MainBranch $args
}
function gswm {
$DevelopBranch = Get-Git-DevelopBranch
git switch $DevelopBranch $args
}
function gts {
git tag -s $args
}
Expand Down
2 changes: 2 additions & 0 deletions src/git-aliases.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ $FunctionsToExport = @(
'gsts',
'gsu',
'gsw',
'gswm',
'gswd',
'gts',
'gunignore',
'gunwip',
Expand Down
18 changes: 18 additions & 0 deletions src/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ function Get-Git-MainBranch {
return 'master'
}

function Get-Git-DevelopBranch {
git rev-parse --git-dir *> $null
if ($LASTEXITCODE -ne 0) {
return
}

$branches = @("dev", "devel", "develop", "development")

foreach ($branch in $branches) {
& git show-ref -q --verify "refs/heads/$branch" *> $null
if ($LASTEXITCODE -eq 0) {
return $branch
}
}

return "develop"
}

# Don't add `Remove-Alias` on PowerShell >= 6.
# PowerShell >= 6 already has built-in `Remove-Alias`.
# Let use built-in `Remove-Alias` on PowerShell >= 6.
Expand Down