Set a Default Push Remote with git

By  on  

During my early days of git usage, my config allowed me to simply type git push instead of git push {origin} {branch_name} which I need to now.  Up until recently I needed to type out the long version...(I know)...which was incredibly annoying because I like using detailed branch names.

I'd finally had enough of the copy and paste branch name madness and decided I wanted git push to always push to my origin and the same branch name:

git config --global push.default current

There are a number of push.default values you can use but in most cases, especially when you have a GitHub workflow, current is likely the value you want to use.  Also, since we're using --global, this will be the default for all repositories!

Recent Features

  • By
    Chris Coyier’s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

Incredible Demos

  • By
    MooTools Zebra Table Plugin

    I released my first MooTools class over a year ago. It was a really minimalistic approach to zebra tables and a great first class to write. I took some time to update and improve the class. The XHTML You may have as many tables as...

  • By
    MooTools Clipboard Plugin

    The ability to place content into a user's clipboard can be extremely convenient for the user. Instead of clicking and dragging down what could be a lengthy document, the user can copy the contents of a specific area by a single click of a mouse.

Discussion

  1. Toby Griffiths

    Thanks for sharing, David. That’ll save me considerable time.

  2. Love this one ! Thank you for sharing.

    For anyone who doesn’t want to set it local, you can also do git push origin –set-upstream per your local branches: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches

  3. How do you set the default for pull? For an open source fork I have, I want git pull to default to git pull upstream special-dev-branch?

  4. Stephen Boesch

    I’d second Devin Rhode’s question

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!