Skip to content
Theme:

Auto setup remote branch and never again see an error about the missing upstream

A little git tip published on Twitter by James Ide went viral a few days ago, and it inspired me to write down this post. You usually see this when you try to git push a local branch that misses a remote upstream.

Failed attempt to git push to a remote branch without setting up the upstream

In most cases, something that we need in this case is to push the current branch to the remote repository under the same branch name. Luckily we have two helpful configuration options to do it.

  1. git config --global --add push.default current
  2. git config --global --add push.autoSetupRemote true

Setting any of these confuguration options (push.default or push.autoSetupRemote) will automatically push to the receiving end a branch with the same name. Additionally, push.autoSetupRemote (added to git 2.37.0) sets the upstream tracking to the corresponding branch.

No more git push --set-upstream origin test && git push again! Bye 👋

Comments

  • N
    Nick Gkloumpos

    It's crazy how a tool you use every day can have such amazing features without you knowing. Thank you for sharing, you just improved my git workflow :)

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Comments like this one, motivate me to keep on writing. Thanks Nick!

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • S
    Sven Stehle

    Thanks for this, this helps a good bit in improving my git workflow :)

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
  • B
    Bouni

    Thank you for this! That's so much value in such a short post, absolutely perfect :-)

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
  • D
    David

    Thank you! I was unclear on how to do this but this breakdown is perfect!

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Awww 🤗 I am glad you found it helpful!

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • M
    Mykola

    Awesome! Thank you very much!

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      I am glad it helped you out 🤗

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • B
    Blackberry

    Awesome !!! Get it! Thanks a lot

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
  • B
    Bruce Lee

    "git config --global --add push.default current" worked for me. Thanks a lot =)

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
  • B
    Bruce Lee

    Thank you

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
  • J
    John Treankler

    Your git config --global --add push.autoSetupRemote true suggestion does exactly what I need, thank you!

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!

Leave a comment

👆 you can use Markdown here

Your comment is awaiting moderation. Thanks!