Created
October 23, 2014 22:01
-
-
Save viktorklang/7525522d9b55be369837 to your computer and use it in GitHub Desktop.
Git Catchup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
######################################################################################################################### | |
# MIT License | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | |
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
######################################################################################################################### | |
# WARNING: USE AT OWN RISK!! YMMV | |
# Applies the commit that currently is point to by HEAD on the current branch in the current git repository | |
# by merging in the upstream and reapplying (cherry-picking) the previous HEAD onto the upstream HEAD | |
function git_catchup() { | |
command git rev-parse --is-inside-work-tree &>/dev/null || return | |
local head=`git rev-parse HEAD` | |
local branch=$(current_branch) | |
echo 'Performing a catchup of branch '$branch':'$head | |
command git reset --hard HEAD^ && git pull origin $branch && git cherry-pick --ff $head | |
if [[ $? -eq 0 ]]; then | |
echo 'Catchup of' $branch 'completed.' | |
else | |
echo 'Catchup of' $branch 'failed, reverting…' | |
command git reset --hard $head | |
echo 'Catchup reverted.' | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment