Skip to content

Instantly share code, notes, and snippets.

@righi
Last active September 12, 2019 17:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save righi/0ca1b7d1bfa3fee03999 to your computer and use it in GitHub Desktop.
Save righi/0ca1b7d1bfa3fee03999 to your computer and use it in GitHub Desktop.
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

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