Skip to content

Instantly share code, notes, and snippets.

@tjmcewan
Last active October 31, 2017 19:15
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjmcewan/6459975 to your computer and use it in GitHub Desktop.
Save tjmcewan/6459975 to your computer and use it in GitHub Desktop.
some options & shortcuts to make git branch management simple and sane

Run these once to setup git options:

git config --global push.default current
git config --global merge.defaultToUpstream true
git config --global branch.autosetupmerge true
git config --global branch.autosetuprebase remote
git config --global alias.cb 'checkout -b'
git config --global alias.ps 'push -u'
git config --global alias.pl '!git fetch -p && git rebase'

Use them like this:

Create & checkout a new branch:

$ git cb new_branch
Switched to a new branch 'new_branch'

Now publish new_branch

$ git ps
Branch new_branch set up to track remote branch new_branch from origin by rebasing.
Everything up-to-date

Get any updates to origin/new_branch & rebase your changes on top

$ git pl
Current branch new_branch is up to date.

All the things

If you want it really straightforward, run this once:
git config --global alias.sync '!git fetch -p && git rebase && git push -u'

and use it on your branches like this:
$ git sync

Caveats

  1. Git will display Branch new_branch … by rebasing. every time you push; it won't hurt anything.
  2. If you work with multiple remotes (for instance, via Heroku), git ps heroku will set the default remote (and hence, rebase target) for your branch to Heroku (almost certainly not what you want).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment