Skip to content

Instantly share code, notes, and snippets.

@Salaander
Last active October 15, 2019 08:18
Show Gist options
  • Select an option

  • Save Salaander/853471aacc4921f72e0db47b03913cea to your computer and use it in GitHub Desktop.

Select an option

Save Salaander/853471aacc4921f72e0db47b03913cea to your computer and use it in GitHub Desktop.
master-to-origin alias to move local master to origin/master and keep local diff
# If you pulled the latest changes and you have commits
# on the master branch that diverge from remote but you do not
# need them and just want to move the master branch locally to origin/master
alias master-to-origin='git co master && git branch master_moved_`date +%m-%d-%Y` && git co origin/master && git branch -D master && git branch master && git branch --set-upstream-to=origin/master master && git checkout master'
# Breakdown
git co master
git branch master_moved_`date +%m-%d-%Y`
git co origin/master
git branch -D master
git branch master
git branch --set-upstream-to=origin/master master
git checkout master
# If you want to generalize it is easy to have the branch name as an attribute to the alias
# This also creates a branch on the old master so we do not lose any references or commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment