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

15
  • Use git log origin/develop.. to see the new commits. Yes, with 2 dots. Commented May 11, 2020 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). Commented May 11, 2020 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) Commented May 11, 2020 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? Commented May 11, 2020 at 18:14
  • Thanks for explaining. But then still, how should I synchronize the two? Commented May 11, 2020 at 18:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.