Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Git not default to "origin master"?

Tags:

git

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?

like image 403
nonopolarity Avatar asked Apr 24 '11 10:04

nonopolarity


People also ask

Does git push default to 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.

Why did git change from master to Main?

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 ...

Why is git push origin master not working?

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.

Is Origin same as master git?

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.


2 Answers

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.

like image 124
Mark Longair Avatar answered Sep 23 '22 21:09

Mark Longair


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.

like image 20
zahanm Avatar answered Sep 20 '22 21:09

zahanm