-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetBranchDifferences.ps1
32 lines (25 loc) · 1.1 KB
/
GetBranchDifferences.ps1
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
## This function will return the differences of a branch on remote compared to the upstream origin/master.
## It will create a temporary branch with the name on line 13.
function GetBranchDifferences
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string]$branch
)
## Replace the branch name below to your hearts desire
$localTemporaryBranchName = 'TEMPORARY.BRANCH.NAME';
$branchWithRefsHead = -join("refs/heads/", $branch);
$existingTemporaryBranch = git for-each-ref --format='%(refname:short)' $branchWithRefsHead;
if ($existingTemporaryBranch -eq $localTemporaryBranchName) {
# Force delete the branch as the HEAD of this branch may be out of sync with master
git branch -D $localTemporaryBranchName
}
git fetch origin;
# Create new branch based on the remote master
git checkout -b $localTemporaryBranchName origin/master;
$branchNameForMerge = -join("origin/", $branch);
git merge $branchNameForMerge --no-commit --no-ff;
Write-Host "Success!" -ForegroundColor Green;
}