Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is using "origin master" really necessary? #716

Open
M4rkD opened this issue Jan 9, 2020 · 2 comments
Open

Is using "origin master" really necessary? #716

M4rkD opened this issue Jan 9, 2020 · 2 comments

Comments

@M4rkD
Copy link
Contributor

@M4rkD M4rkD commented Jan 9, 2020

I'm not convinced (in the current form of the notes) that specifying "origin master" everywhere adds enough value to be worth including.

Typically, I'd always write "git pull" or "git push" and never worry about the "origin master" part.

I can't think of many sensible cases where a user would want to specify the "origin master" variant:

  • someone might be on one branch whilst pushing another, but I don't think we've taught enough here to worry about that.
  • if you're on a branch other than master that you've created locally, then you get the potentially confusing message:
fatal: The current branch another-branch has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin another-branch

I admit this is slightly confusing, but I don't think that this message is worth teaching that we should be typing "git pull" and "git push" everywhere.

Anyone else have any thoughts on this?

@omsai

This comment has been minimized.

Copy link

@omsai omsai commented Jan 9, 2020

git push origin master is always guaranteed to work whereas you will always see the git push message you quoted when your remote is a bare repository and the master branch does not yet exist on the remote. You can reproduce this as follows:

omsai@xm2:~$ cd /tmp/
omsai@xm2:/tmp$ mkdir repo-local
omsai@xm2:/tmp$ cd repo-local
omsai@xm2:/tmp/repo-local$ git init
Initialized empty Git repository in /tmp/repo-local/.git/
omsai@xm2:/tmp/repo-local$ touch test.txt
omsai@xm2:/tmp/repo-local$ git add test.txt
omsai@xm2:/tmp/repo-local$ git commit -m "Initial commit"
[master (root-commit) 9aa30c7] Initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt
omsai@xm2:/tmp/repo-local$ git remote add origin /tmp/repo-remote
omsai@xm2:/tmp/repo-local$ mkdir /tmp/repo-remote
omsai@xm2:/tmp/repo-local$ git -C /tmp/repo-remote init --bare
Initialized empty Git repository in /tmp/repo-remote/
omsai@xm2:/tmp/repo-local$ git push
fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin master

omsai@xm2:/tmp/repo-local$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 217 bytes | 217.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /tmp/repo-remote
 * [new branch]      master -> master
omsai@xm2:/tmp/repo-local$ 

Talking about "origin master" does not add much cognitive load. You should have already explained what "master" is when you explain the first commit message, and origin is the name we gave to the remote URL:

omsai@xm2:/tmp/repo-local$ git remote -v
origin	/tmp/repo-remote (fetch)
origin	/tmp/repo-remote (push)
omsai@xm2:/tmp/repo-local$ 
@M4rkD

This comment has been minimized.

Copy link
Contributor Author

@M4rkD M4rkD commented Jan 9, 2020

Thanks for your comment @omsai, much appreciated. You're absolutely right of course, I neglected the case of pushing an existing local to a bare remote, that does complicate things.

Having said that, I'm a little bit convinced, but not fully convinced (yet?).

The most likely scenario I see for a bare repo is a new repo on services like github, bitbucket etc - but they're pretty good at being explicit about how to upload existing (and new) code. I just don't see this as a major stumbling block.

Otherwise users might create a bare repo themselves (using commands we haven't taught them), or someone else creates it for them, or they start messing around with remotes. But to my mind these are all beyond the scope of the material.

I suspect there are other cases that I'm forgetting, but I can't think of anything else right now? Are there other important cases I've overlooked here?

As to the comment

Talking about "origin master" does not add much cognitive load. You should have already explained what "master" is when you explain the first commit message, and origin is the name we gave to the remote URL

I'm interested in the opinion of the community here, because this is different to my experience. I've not found master trivial to deal with without the concept of a branch. I certainly haven't got a foolproof sentence or two to introduce it, I would be interested if anyone else does. If this can be done, it would benefit from being in the notes.

Same goes for explaining origin without multiple remote, but I find this one easier to avoid explaining.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.