0

git status on the server returns:

On branch develop
Your branch is ahead of 'origin/develop' by 14 commits.
  (use "git push" to publish your local commits)
nothing to commit, working tree clean

My goal is to get the git branch on gitlab.com and on the server synchronized. When I look at the difference between the two, the commits that it states that remote on the server is ahead, are commits I believe are actually there on gitlab.com.

I did the following on the server:

  1. git status returns "Your branch is ahead of 'origin/develop' by 14 commits."
  2. git reset --soft HEAD~1
  3. git status now returns "branch is up-to-date with origin/develop. Changes to be committed:" and then a list with changes.
  4. git reset --hard
  5. git status now returns "branch is up-to-date with origin/develop. Nothing to commit."
  6. git log is missing the latest commits and therefore essentially disagrees with step 5.
  7. git pull origin develop This pulls various changes (how is that possible since step 5 returns "up-to-date"...?).
  8. git status returns the original message "ahead of 'origin/develop' by 14 commits" and I'm back where I started.

I don't understand this. How can the server return to being ahead of gitlab.com (step 8) after pulling from gitlab...? I removed all changes on the server and just did a pull...

Nick
  • 3,496
  • 7
  • 42
  • 96
  • Use `git log origin/develop..` to see the new commits. Yes, with 2 dots. – phd May 11 '20 at 15:48
  • If after step 5 I enter `git log origin/develop..`, this returns nothing, not even a blank line... And if I do it after step 7, it returns a list of commits that are on gitlab.com, so I don't see why it would consider the server to be ahead these commits in comparison to gitlab.com (after all, it just pulled them from gitlab.com). – Nick May 11 '20 at 17:55
  • perhaps you forgot to fetch data from remote (as far as I remember git status compare with a local version of the branch)? git fetch -> git pull OR git pull -f (in case of the branch name the same) – Evgeniy May 11 '20 at 18:11
  • Keep in mind that when `git status` says "Your branch is ahead of 'origin/develop' by 14 commits", it is not looking at gitlab. It is looking at a _local_ branch, a _tracking_ branch which may not be up to date with what's on gitlab. — Also I'm confused by your statements "`git status` on the server" and "I did the following _on the server_"... really? You gave those commands through ssh or something? Why would you ever do such a thing? – matt May 11 '20 at 18:14
  • Thanks for explaining. But then still, how should I synchronize the two? – Nick May 11 '20 at 18:16
  • Also I don't understand the title, "get origin and remote the same". Origin _is_ the remote. – matt May 11 '20 at 18:21
  • Thanks, I've updated the title – Nick May 11 '20 at 18:27
  • But it still doesn't make sense. The local is not the server. The remote, origin, is the server. The local is your computer. That is why I'm asking about your use of the word "server" everywhere. Do you really mean "server" or do you mean the opposite, the "local"? – matt May 11 '20 at 18:31
  • So I use gitlab.com, which is the origin. And I have a Linux server, which is what I refer to when using "server". On the server, I would like to do a pull from gitlab.com, and then have `git status` say it's up-to-date. – Nick May 11 '20 at 18:34
  • And how do you talk to the Linux server? Are you using ssh? – matt May 11 '20 at 18:43
  • OK I'm going to suggest that this is a duplicate of https://stackoverflow.com/questions/7365415/pull-only-repos-git-status-saying-the-branch-is-ahead-of-origin-master-why. – matt May 11 '20 at 18:46
  • What version of Git is installed on this server? I bet it is Git 1.7.1, 1.7.9, or 1.8.1. If that's the case, the problem is that `git pull` is *bypassing the update of `origin/develop`* as it used to do in those ancient versions of Git. – torek May 11 '20 at 19:08
  • @torek Yes, that's what I was referring to in the duplicate link I pointed to. – matt May 11 '20 at 19:14
  • @matt: that's right, but with Git version 1.8.2 or newer, `git pull origin develop` would actually update `origin/develop` after all. (It would *not* update the other `origin/*` names, which is another reason to avoid `git pull` in favor of a separate`git fetch`... Ah, Git.) – torek May 11 '20 at 19:18
  • @torek Yes, thanks for clarifying that even clearer. :) – matt May 11 '20 at 19:20

1 Answers1

2
  1. git status returns "Your branch is ahead of 'origin/develop' by 14 commits."

This does not mean that your branch is ahead of the remote (origin). origin/develop is a local branch. It is a remote tracking branch, but it is not updated automatically. The way to update it is to say git fetch — something that you never report having said.

  1. git reset --soft HEAD~1
  2. git status now returns "branch is up-to-date with origin/develop. Changes to be committed:" and then a list with changes.
  3. git reset --hard
  4. git status now returns "branch is up-to-date with origin/develop. Nothing to commit."
  5. git log is missing the latest commits and therefore essentially disagrees with step 5.

I don't know why you did any of that. You chopped off a bunch of commits from develop. Why would you deliberately lame your local branch?

Also, you are wrong about 6: having lamed develop, you have caused it to agree with origin/develop, which is still sitting there unchanged. They are absolutely in agreement.

  1. git pull origin develop This pulls various changes (how is that possible since step 5 returns "up-to-date"...?).

It's possible because, once you have lamed develop, the remote is ahead of you. So you pull from the remote, and now your develop gets the commits from the remote that you just chopped off it.

  1. git status returns the original message "ahead of 'origin/develop' by 14 commits" and I'm back where I started.

Because you still have not updated origin/develop by saying git fetch.

So basically you've gone around in circles because (a) you don't know what origin/develop is and (b) you keep not updating origin/develop. Update it! Say git fetch, and you will then discover through git status what the actual situation is. I suspect that you will find that you are completely up to date and all is well.

matt
  • 515,959
  • 87
  • 875
  • 1,141