git push autoSetupRemote

Опубликовано: 31 Октябрь 2024
на канале: Mark Shust
2,900
88

Want an easier way to push branches in Git?

Normally when you create and checkout a branch, make a commit, and then try to push it upstream -- you'll get an error. This is because the branch name does not yet exist on the remote server.

I always just copied & pasted the line provided to setup the remote branch, but this is repetitive and totally not needed, because there is a much better way.

When making a push, you'll see a reference to "push.autoSetupRemote". This is a subtle hint that we can automatically push branches upstream, without the need to add it to the git config.

Just run the following command:
git config --global --add --bool push.autoSetupRemote true

Now, when you create a new branch and issue a "git push", this git config will be applied, and Git will automatically create the related remote branch and upload it to the remote server -- without you needing to do anything else.

#git #opensource