Skip to content

Instantly share code, notes, and snippets.

@matthewadowns
Last active October 28, 2022 20:31
Show Gist options
  • Save matthewadowns/32a549719816ab3a52f0c997ba7804c4 to your computer and use it in GitHub Desktop.
Save matthewadowns/32a549719816ab3a52f0c997ba7804c4 to your computer and use it in GitHub Desktop.
Quickly push a new branch upstream when checking out a new branch with this shell function and alias
# Add this to your shell profile (e.g. .zshrc or .bashrc)
publishBranch() {
git checkout -b $1
git push -u origin $1
}
alias gcb=publishBranch
#########################
# Usage
# > gcb my-new-branch
# Branch 'my-new-branch' set up to track local branch 'master' by rebasing.
# Switched to a new branch 'my-new-branchh'
# Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
# remote:
# remote: Create a pull request for 'my-new-branch' on GitHub by visiting:
# remote: https://github.com/YOURORG/SOMEREPO/pull/new/my-new-branch
# remote:
# To github.com:YOURORG/SOMEREPO.git
# * [new branch] my-new-branch -> my-new-branch
# Branch 'my-new-branch' set up to track remote branch 'my-new-branch' from 'origin' by rebasing.
#########################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment