-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit.ps1
More file actions
36 lines (30 loc) · 905 Bytes
/
git.ps1
File metadata and controls
36 lines (30 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# git fetch a branch
function gf([string]$branch) {
Write-Host "fetching $branch"
& git fetch origin $branch
if($LASTEXITCODE -ne 0) {
throw "Failed to fetch branch $branch"
}
}
# git fetch and checkout branch
function gfc([string]$branch) {
gf -branch $branch
$uncommited = & git status -s --untracked-files=no
if(![string]::IsNullOrWhiteSpace($uncommited)) {
git status
$choice = Read-Host -Prompt "You have uncommitted local changes. Press 'Y' to continue."
if($choice -ne "Y") {
return
}
}
$curBranch = & git rev-parse --abbrev-ref HEAD
if($curBranch -eq $branch) {
& git reset --hard origin/$branch
} else {
& git show-ref --heads "$branch"
if($LASTEXITCODE -eq 0){
& git branch -D $branch
}
& git checkout -f -b $branch "origin/$branch"
}
}