Created
November 26, 2014 17:26
-
-
Save todb-r7/3fbee1a9e7b36d82ca55 to your computer and use it in GitHub Desktop.
Safely publish local changes to upstream master
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
[alias] | |
# A pretty and short commit log which notes signed commits | |
nicelog = log --pretty=format:'%Cred%h%Creset -%Creset %s %Cgreen(%cr) %C(bold blue)<%aE>%Creset [%G?]' | |
# Get the current tracking branch, eg, upstream/master | |
tracking = !"git branch -vv | grep \\* | sed 's#.*\\[\\(.*\\)[]].*#\\1#' | cut -f 1 -d :" | |
# Get the current tracking branch remote, eg, upstream | |
tracking-remote = !"git tracking | cut -f 1 -d /" | |
# Fetch and rebase from the current tracking remote, preserving and re-signing local merges. | |
fetch-preserve-merges = !"git fetch $(git tracking-remote) && \ | |
git rebase --preserve-merges && \ | |
git nicelog -5 && \ | |
git commit --amend -S; #" | |
# Publish changes in local upstream-master to upstream/master, | |
# preserving local merges and resigning them along the way. | |
publish = !"git fetch-preserve-merges && git push upstream upstream-master:master" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem
I'm merging a pull request, working on, it, testing it, etc. Once I'm done, I want to push it, but sometimes, someone else beats me to pushing to upstream/master. If I git pull -r, I'll rebase and wipe out my local merge commit, and that's sad.
The solution
This set of aliases will get the current state of upstream/master, rebase the local branch with the upstream changes, preserve my merge commit, and resign it. Finally, it'll push to upstream (without forcing).
I like having the last 5 commits displayed at me, too, just so I can see what's happened recently.
This is largely based on the advice by Glen Madden. Thanks!
Example usage:
This was a case where I landed #4264 while joev-r7 was landing #4265. Seems to have worked like a charm.