DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for βš™ This new GIT push config will save you lot of frustration!
Leonardo Montini for This is Learning

Posted on • Updated on

βš™ This new GIT push config will save you lot of frustration!

If you have 59 seconds and in particular you're also on mobile, you might enjoy watching the YouTube #Shorts video.

YouTube Video


When creating and pushing a new branch, you will get this error:

fatal: The current branch feature/my-cool-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin feature/my-cool-branch

Enter fullscreen mode Exit fullscreen mode

Since version 2.37 git has introduced a new config, called push.autoSetupRemote that covers this case.

From the official documentation:

If set to "true" assume --set-upstream on default push when no upstream tracking exists for the current branch; this option takes effect with push.default options simple, upstream, and current. It is useful if by default you want new branches to be pushed to the default remote (like the behavior of push.default=current) and you also want the upstream tracking to be set. Workflows most likely to benefit from this option are simple central workflows where all branches are expected to have the same name on the remote.

First of all, make sure you're on version 2.37 or higher by just running

git --version
Enter fullscreen mode Exit fullscreen mode

You can download the latest version from https://git-scm.com/ or via command line, for example with a mac using homebrew:

brew install git
Enter fullscreen mode Exit fullscreen mode

Now that you're all set, just run this command:

git config --global push.autoSetupRemote true
Enter fullscreen mode Exit fullscreen mode

It will set in your global git configuration file the value true to push.autoSetupRemote.

With that set, all first-time push on new branches will automatically set the default upstream.

To see it live, you can have a look at this short YouTube video.
YouTube Video


Thanks for reading this post, I hope you find it interesting!
Feel free to follow me to get notified when new articles are out ;)



You can also follow me on Twitter and YouTube!

Twitter YouTube

Top comments (19)

Collapse
balastrong profile image
Leonardo Montini Author

Did you know about this new command?
It has been released just a few weeks ago, I noticed it by casually scrolling on Twitter!

Let me know if you heard of some other cool features that have been recently introduced!

Collapse
natescode profile image
Nathan Hedglin

I recently learned about it and added it to my git config along with all my aliases

Collapse
evomatic profile image
Evan Trujillo

Awesome list here, this is quite useful! :)

Thread Thread
natescode profile image
Nathan Hedglin

Thanks! I've been compiling it for awhile.

Collapse
jmfayard profile image
Jean-Michel Fayard πŸ‡«πŸ‡·πŸ‡©πŸ‡ͺπŸ‡¬πŸ‡§πŸ‡ͺπŸ‡ΈπŸ‡¨πŸ‡΄

Thanks a lot, someone mentioned it in a recent rant I wrote about git, but I didn't know how to use it. This should have been the default from the start but better late than never.

Collapse
jitendrakr54 profile image
JITENDRA KUMAR GUPTA

Superb! Thanks for sharing.

Collapse
shshank profile image
Shshank

Thanks a lot for sharing this.

Collapse
supermari0s profile image
ΞœΞ¬ΟΞΉΞΏΟ‚

Nice one ! Thanks !

Collapse
chrysthianprudencio profile image
chrysthianprudencio

nice one

Collapse
shirobachi profile image
Shirobachi

Do you mind update yet link? It's doesn't work on my device at least

Collapse
balastrong profile image
Leonardo Montini Author

Sure! What link is not working?

Collapse
shirobachi profile image
Shirobachi

Oh sorry, it would be link to my short first at the begging of post and at the end too

Thread Thread
balastrong profile image
Leonardo Montini Author

youtube.com/shorts/KrgNpJA0sX4

This is the link, it works for me though πŸ€”

Thread Thread
shirobachi profile image
Shirobachi

Hmm so maybe it's some country restrictions or STH on yt side anyway thanks and sorry for confusion

Thread Thread
balastrong profile image
Leonardo Montini Author

No worries!

If you can see the channel, it's the most recent video here youtube.com/c/DevLeonardo

Collapse
goodevilgenius profile image
Dan Jones

How does it decide which remote to push to? I regularly have multiple remotes for any of my repos.

Collapse
andrewbaisden profile image
Andrew Baisden

This is going to be handy.

Collapse
uzair004 profile image
Muhammad Uzair

Thanks for sharing, i remember it was pain the rear when I use to have git cmd. I use GitHub desktop these days

Collapse
dshung1997 profile image
Sy Hung Doan

Cool. Before this, I used gpsup (git plugin on oh-my-zsh)

🌚 Life is too short to browse without dark mode