You should almost never have to do a push of the form
$ git push origin something:somewhere
This is a good way to accidentally create a branch on the remote that you didn’t mean to, which an admin then has to delete. In fact, it’s precisely how you create a new branch on the remote:
$ git push origin new_branch:new_branch
“But Kate,” you say, “I keep getting annoying messages that look like this when I just run git push:”
warning: You did not specify any refspecs to push, and the current remote warning: has not configured any push refspecs. The default action in this warning: case is to push all matching refspecs, that is, all branches warning: that exist both locally and remotely will be updated. This may warning: not necessarily be what you want to happen. warning: warning: You can specify what action you want to take in this case, and warning: avoid seeing this message again, by configuring 'push.default' to: warning: 'nothing' : Do not push anything warning: 'matching' : Push all matching branches (default) warning: 'tracking' : Push the current branch to whatever it is tracking warning: 'current' : Push the current branch
“Why does it do that?”
It does that because, for whatever reason, your config file isn’t set correctly. You can run
$ git config push.default matching
to set the default (back to) what it should be: This pushes all local branches that have a matching “origin/” branch to the remote.
This normally gets set up correctly when you clone a repo, but sometimes it gets confused for one reason or another, so resetting it manually will fix it.
“What if I have a bunch of commits but only want to push one particular branch?”
There’s two ways to do that:
$ git checkout branch-i-want-to-push $ git push origin HEAD - or - $ git push origin branch-i-want-to-push
(Yes, that last one will create the branch on origin if it doesn’t exist there already, so be careful.)
“I tried to do a pull and it said I couldn’t — something about a ‘non-fast-forward merge???’”
This means your local tree is dirty. You should always commit before you do a pull — remember, unlike Subversion or CVS, a commit only affects your local repository, not the remote. If you aren’t sure that you want to commit the current changes, you can
$ git add <whatever you've changed> $ git stash save $ git pull $ git stash pop
See http://schacon.github.com/git/git-stash.html for more on using the stash.
“I tried to do a push and it said I couldn’t — something about a ‘non-fast-forward merge???’”
There are two possible reasons for this:
- you need to pull
- you’ve rebased commits that have already been pushed
In the first instance, you just need to pull (and fix any resulting merge conflicts). In the second instance, you are severely screwed: Most remote repositories will not allow you to push something that’s been rebased after being pushed. This is to keep you from rewriting history on the official repository. You need to revert your rebase.