Posted By: Anonymous
I created a local branch which I want to ‘push’ upstream. There is a similar question here on Stack Overflow on how to track a newly created remote branch.
However, my workflow is slightly different. First I want to create a local branch, and I will only push it upstream when I’m satisfied and want to share my branch.
- How would I do that? (my google searches did not seem to come up with anything).
- How would I tell my colleagues to pull it from the upstream repository?
UPDATE With Git 2.0 there is a simpler answer I have written below: https://stackoverflow.com/a/27185855/109305
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