Skip to content

Instantly share code, notes, and snippets.

@righi
Last active Sep 12, 2019
Embed
What would you like to do?
git-reup
#!/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:
# http://gist.github.com/249223
#
# Stolen from Ryan Tomayko
# http://github.com/rtomayko/dotfiles/blob/rtomayko/bin/git-up
# and then Zach Holman
# https://github.com/holman/dotfiles/blob/master/bin/git-up
# and then Barijaona Ramaholimihaso
# https://gist.github.com/barijaona/3194807
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$/
end
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/^/ /'"
end
puts "Log:"
system "git log --color --pretty=oneline --abbrev-commit #{old_head}.. | sed 's/^/ /'"
end
@markrebec
Copy link

markrebec commented Jan 9, 2015

Add this to your .gitconfig to enable git reup:

[alias]
  reup = !/path/to/your/git-reup

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