I use the following command to push to my remote branch:
git push origin sandbox
If I say
git push origin
You can set up default behavior for your git with push.default
git config push.default current
or if you have many repositories and want the same for all then
git config --global push.default current
The current in this setup means that by default you will only push the current branch when you do git push
Other options are:
UPDATE - NEW WAY TO DO THIS
As of Git 1.7.11 do the following:
git config --global push.default simple
This is a new setting introduced that works in the same way as current, and will be made default to git from v 2.0 according to rumors
I just committed my code to a branch and pushed it to github, like this:
git branch SimonLowMemoryExperiments
git checkout SimonLowMemoryExperiments
git add .
git commit -a -m "Lots of experimentation with identifying the memory problems"
git push origin SimonLowMemoryExperiments
(March 2012)
Beware: that default "matching
" policy might change soon
(sometimes after git1.7.10+):
See "Please discuss: what "git push" should do when you do not say what to push?"
In the current setting (i.e.
push.default=matching
),git push
without argument will push all branches that exist locally and remotely with the same name.
This is usually appropriate when a developer pushes to his own public repository, but may be confusing if not dangerous when using a shared repository.The proposal is to change the default to '
upstream
', i.e. push only the current branch, and push it to the branch git pull would pull from.
Another candidate is 'current
'; this pushes only the current branch to the remote branch of the same name.What has been discussed so far can be seen in this thread:
http://thread.gmane.org/gmane.comp.version-control.git/192547/focus=192694
Previous relevant discussions include:
To join the discussion, send your messages to: git@vger.kernel.org
A git push will try and push all local branches to the remote server, this is likely what you do not want. I have a couple of conveniences setup to deal with this:
Alias "gpull" and "gpush" appropriately:
In my ~/.bash_profile
get_git_branch() {
echo `git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
}
alias gpull='git pull origin `get_git_branch`'
alias gpush='git push origin `get_git_branch`'
Thus, executing "gpush" or "gpull" will push just my "currently on" branch.
Here is a very handy and helpful information about Git Push: Git Push: Just the Tip
The most common use of git push is to push your local changes to your public upstream repository. Assuming that the upstream is a remote named "origin" (the default remote name if your repository is a clone) and the branch to be updated to/from is named "master" (the default branch name), this is done with: git push origin master
git push origin
will push changes from all local branches to matching branches the origin remote.
git push origin master
will push changes from the local master branch to the remote master branch.
git push origin master:staging
will push changes from the local master branch to the remote staging branch if it exists.
You can change that default behavior in your .gitconfig, for example:
[push]
default = current
To check the current settings, run:
git config --global --get push.default