Skip to content

Software Engineer at Polygon

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!

Leave a comment

👆 you can use Markdown here

Your comment is awaiting moderation. Thanks!