⚙ This new GIT push config will save you lot of frustration!

Leonardo Montini - Aug 2 '22 - - Dev Community

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

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player