I tried many times doing a
git pull
and it says the branch is not specified. So the answer in How do you get git to always pull from a specific branch? seems to work.
But I wonder, why doesn’t Git default to master branch? If nothing is specified, doesn’t it make sense to mean the master branch?
git tries to use sensible defaults for
git pullbased on the branch that you’re currently on. If you get the error you refer to fromgit pullwhile you’re onmaster, that means you haven’t configured an upstream branch formaster. In many situations this will be configured already – for example, when you clone from a repository,git clonewill set up theoriginremote to point to that repository and set upmasterwithorigin/masteras upstream, sogit pullwill Just Work™.However, if you want to do that configuration by hand, you can do so with:
… although as of git 1.8.0 you should use
--set-upstream-to, since the former usage is not deprecated due to be confusingly error-prone. So, for git 1.8.0 and later you should do:Or you could likewise set up the appropriate configuration when pushing with:
… and
git pullwill do what you want.