Skip to content

Instantly share code, notes, and snippets.

@MatteoJoliveau
Created January 26, 2018 09:26
Show Gist options
  • Save MatteoJoliveau/afd436fcb81a85afecbfae7ef0e1aabb to your computer and use it in GitHub Desktop.
Save MatteoJoliveau/afd436fcb81a85afecbfae7ef0e1aabb to your computer and use it in GitHub Desktop.
Automatically pull a git branch and merge it in another branch. Useful to sync a Git Flow feature branch with develop
# param(
# [Parameter(Mandatory = $false)] [switch]$help = $help,
# [Parameter(Mandatory = $true)] [string]$source = "develop",
# [Parameter(Mandatory = $true)] [string]$target,
# [Parameter(Mandatory = $false)] [switch]$flow = $false
# )
param(
[switch]$help = $help,
[string]$source = "develop",
[string]$target,
[switch]$flow = $false
)
function GetFullTarget () {
if ($flow) {
return "feature/$target"
}
else {
return $target
}
}
function PrintHelp () {
Write-Output "Usage:`n`t update-branch -source develop -target my-feature-branch -flow
`n`t-source: source branch to pull
`n`t-target: target brench to merge into
`n`t-flow use git flow target naming (-target hello will be converted in feature/hello)
"
}
if ($help) {
PrintHelp
return
}
$fullTarget = GetFullTarget
git checkout $source
git pull
git checkout $fullTarget
git merge $source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment