Skip to content

Instantly share code, notes, and snippets.

@robmiller
Last active December 24, 2016 05:09
Show Gist options
  • Save robmiller/5686166 to your computer and use it in GitHub Desktop.
Save robmiller/5686166 to your computer and use it in GitHub Desktop.
A few useful commands for working with branches
# git branch-name: prints the name of the branch in a safe/scriptable/non-porcelain way
# git publish: publishes the current branch on the remote "origin", using the same name as the current branch
# git unpublish: deletes the remote branch with the same name as the current one (potentially destructive)
# git recreate: given a branch name, recreates the branch with that name from the latest master. Deletes both the local and remote copy of the branch first. Very destructive, use with caution
branch-name = "!git rev-parse --abbrev-ref HEAD"
publish = "!git push -u origin $(git branch-name)"
unpublish = "!git push origin :$(git branch-name)"
recreate = "!f() { [[ -n $@ ]] && git checkout \"$@\" && git unpublish && git checkout master && git branch -D \"$@\" && git checkout -b \"$@\" && git publish; }; f"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment