-1

I seem to have a weird difference in origin/master

The commands are run in order

I am on the master branch and ran the commands in sequence

git pull origin master

Same output:

git diff origin/master 
git diff remotes/origin/master

Different output:

git diff origin/master
git diff origin master

Can someone explain why is this so?

Thanks.

aceminer
  • 4,089
  • 9
  • 56
  • 104
  • `origin/master` is just a short name for `remotes/origin/master`, so it makes sense that they both give the same output. `git diff origin master` is the difference between `origin/master` and the local `master`; `git diff origin/master` is the difference between `origin/master` and the working tree. You didn’t actually say what any of the output was, though, so not sure what’s weird about it. – Ry- Feb 03 '18 at 09:56
  • well the difference is that there were more changes observed in `git diff origin master` as opposed to `git diff origin/master` – aceminer Feb 03 '18 at 09:57
  • So… do you have any changes in the working tree? (Run `git diff`) – Ry- Feb 03 '18 at 09:58
  • Possible duplicate of [In Git, what is the difference between origin/master vs origin master?](https://stackoverflow.com/questions/18137175/in-git-what-is-the-difference-between-origin-master-vs-origin-master) – phd Feb 03 '18 at 14:14
  • `git pull` is a weird command that will lead you astray. Avoid it for now—it's meant to be a convenient shortcut, `git fetch` followed by a second Git command, usually `git merge`. But it uses this peculiar spelling—`origin master`—in an unusual way that won't make sense yet. – torek Feb 03 '18 at 17:04

1 Answers1

1

When you have use origin, it itself means origin/master i.e. your master branch on remote server. For specifying some other branch on remote server, you will need branch name. E.g origin/mybranch123.

And When you type master (or any other branch name) alone, without origin you are referring to local branch.

Now correct way to see the diff is git diff branch_name1 branch_name2

So you see the actual result when you are typing the last command. In typing git difforigin/master you are just specificying 1 branch name. Same is the case with remotes/origin/master as it is same as origin/master.

tryingToLearn
  • 10,691
  • 12
  • 80
  • 114