I created a local branch. How do I push it to the remote server?
UPDATE: I have written a simpler answer for Git 2.0 here.
Simple Git 2.0+ solution:
As of Git 2.0, the behavior has become simpler:
You can configure git with
push.default = current to make life easier:
I added this so now I can just push a new branch upstream with
$ git push -u
-u will track remote branch of the same name. Now with this configuration, you will auto-guess the remote reference to git push. From git.config documentation:
Defines the action git push should take if no refspec is explicitly given.
push.default = current– push the current branch to update a branch with the
same name on the receiving end. Works in both central and non-central workflows.
For me, this is a good simplification of my day-to-day Git workflow. The configuration setting takes care of the ‘usual’ use case where you add a branch locally and want to create it remotely. Also, I can just as easily create local branches from remotes by just doing
git co remote_branch_name (as opposed to using
I know this question and the accepted answers are rather old, but the behavior has changed so that now configuration options exist to make your workflow simpler.
To add to your global Git configuration, run this on the command line:
$ git config --global push.default current