Set up a quicker alias for `git push -u origin $BRANCH_NAME` and `git push` at the same time

Viewed 730

When I want to push changes on a branch that already has upstream branch, git push is all I need. But when there's no current upstream branch, I have to type out git push -u $BRANCH_NAME.

I create new branches all the time (for every feature that I work on, so it's about one every two hours or so). I also make typos sometimes. It gets irritating. How can I create an alias that would automatically resolve to git push or git push -u $BRANCH_NAME and wouldn't require me to type out branch name?

1 Answers

To get your wanted behavior, put this into your ~/.gitconfig:

[push]
    default = current

(as usual, $ git config --global push.default current does this for you.)

There's an explanation of the options of push.default here:

current - push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows.

-- https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault

Related