Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Last active August 4, 2016 19:01
Show Gist options
  • Select an option

  • Save kristopherjohnson/b72241f81bf04aeea512c7917c9725a7 to your computer and use it in GitHub Desktop.

Select an option

Save kristopherjohnson/b72241f81bf04aeea512c7917c9725a7 to your computer and use it in GitHub Desktop.
bash/zsh function for pushing a new git branch to remote
# Get the current git branch name
git-branch-name() {
git symbolic-ref --short HEAD
}
# Push new branch to origin and set up tracking
git-push-new-branch() {
git push -u origin $(git-branch-name)
}
@kristopherjohnson
Copy link
Author

kristopherjohnson commented Aug 4, 2016

Typical use:

source git-push-new-branch.sh     # or add it to your .bashrc

git checkout master
git checkout -b my-new-branch
# ... make changes ...
git commit -am "I created a new branch with some changes"
git-push-new-branch   # pushes to origin/my-new-branch and local branch will track it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment