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 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.
GitHub took action based on the Conservancy's suggestion and moved away from the term master when a Git repository is initialized, "We support and encourage projects to switch to branch names that are meaningful and inclusive, and we'll be adding features to Git to make it even easier to use a different default for new ...
If git push origin master not working , all you need to do is edit that file with your favourite editor and change the URL = setting to your new location. Assuming the new repository is correctly set up and you have your URL right, you'll easily be able to push and pull to and from your new remote location.
The term "git origin master" is used in the context of a remote repository. It is used to deal with the remote repository. The term origin comes from where repository original situated and master stands for the main branch. Let's understand both of these terms in detail.
git tries to use sensible defaults for git pull
based on the branch that you're currently on. If you get the error you refer to from git pull
while you're on master
, that means you haven't configured an upstream branch for master
. In many situations this will be configured already - for example, when you clone from a repository, git clone
will set up the origin
remote to point to that repository and set up master
with origin/master
as upstream, so git pull
will Just Work™.
However, if you want to do that configuration by hand, you can do so with:
git branch --set-upstream master origin/master
... 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:
git branch --set-upstream-to origin/master
Or you could likewise set up the appropriate configuration when pushing with:
git push -u origin master
... and git pull
will do what you want.
As mentioned above, git clone
sets all the defaults appropriately.
I've found pushing with the -u
option to be the easiest to set things up with an existent repo.
git push -u origin master
You can check what has been remotely configured using
git remote -v
See git help remote
for more information on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With