Skip to content

Instantly share code, notes, and snippets.

Last active Sep 12, 2019
What would you like to do?
#!/usr/bin/env ruby
# Usage: git-up
# git-reup
# Like git-pull but show a short and sexy log of changes
# immediately after merging (git-up) or rebasing (git-reup).
# Inspired by Kyle Neath's `git up' alias:
# Stolen from Ryan Tomayko
# and then Zach Holman
# and then Barijaona Ramaholimihaso
require 'shellwords'
pull_args = ARGV.to_a
rebase = File.basename($0) == 'git-reup'
stashed = false
old_head = `git rev-parse HEAD`.chomp
exit($?.to_i) unless $? == 0
if rebase
pull_args.push '--rebase'
msg = `git stash save "Auto-stash by #{File.basename($0)} script"`
stashed = msg !~ /^No local changes to save$/
system "git pull #{pull_args.shelljoin}"
updated = (old_head != `git rev-parse HEAD`.chomp)
system "git stash pop --quiet" if stashed && rebase
if updated
if rebase
puts "Diffstat:"
system "git --no-pager diff --color --stat #{old_head}.. | sed 's/^/ /'"
puts "Log:"
system "git log --color --pretty=oneline --abbrev-commit #{old_head}.. | sed 's/^/ /'"
Copy link

markrebec commented Jan 9, 2015

Add this to your .gitconfig to enable git reup:

  reup = !/path/to/your/git-reup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment