Git push to a new branch

The setting in git to make it push to the new branch with the same name

git config --global push.default current

For my blog's 100's record I am happy it returns to the original purpose. To serve as a notepad for myself and to store things I have searched for far too many times.

The setting above makes the default developer's git flow to be just a tiny bit better. A simple git push on a branch that does not track any remote branch yet will create a new branch with the same name on the remote and push there.

In short, instead of

$ git checkout -b feature-name
$ # <changes>
$ git commit
$ git push
fatal: The current branch stats has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin feature-name

$ git push -u origin feature-name
$ # done

It will be as simple as

$ git checkout -b feature-name
$ # <changes>
$ git commit
$ git push
$ # done

Note that you can always set the local branch to track a remote branch with a different name. The behaviour only changes for the branches that do not track (yet) anything.

Posted On

Category:

Tags: / /