Automatic Git Upstream on Push


Hardships

You’ve gone to push up your branch and feature work only to get hit, yet again, with:

fatal: The current branch has no upstream branch[...]

followed by directions to use the upstream command. You’ve done this like 10 times in the past 2 months, “I have to stop doing this”, you think to yourself. Your thoughts are correct and you do and it’s as simple as 1 (one) command.

git config --global push.autoSetupRemote true

Successes

Voila! Every time you go to push a new branch git will automatically set upstream origin for you, what a blessing!

Your global gitconfig should now have an entry under [push]:

# other stuff

[push]
    autoSetupRemote = true

Multiple Remote Hosts

I think this makes a lot of sense if you are only using one repo host for all of your projects like Github. I get that not everyone does that and many fall into situations were work is on BitBucket, personal is in GitHub, and a lot of your freelancing clients are on GitLab. For something like that maybe you have a global that has this [push] hook and then a <directory>/.gitconfig for work and then personal.