karthick87
karthick87

Reputation: 53

Local code is not in sync with Remote Repository

We are facing the below issue, where our local code is not in sync with Remote Repository.

We have recently pushed a code (which is not maintained in Git Earlier) to Git Repository.After pushing the local copy to Git Repository we realized, that we have some updated local copy in another path in our local machine and we are not trying to push these things to Remote Repository. While Pushing the changes we are hitting into below issue.

$ git push origin master
To https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.


$ git branch -r
  origin/master

$ git pull origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
 * branch            master     -> FETCH_HEAD
Already up to date.

$ git push origin master
To https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

$ git pull --rebase origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
 * branch            master     -> FETCH_HEAD
Already up to date.
fatal: It seems that there is already a rebase-apply directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr ".git/rebase-apply"
and run me again.  I am stopping in case you still have something valuable there.

$ git pull origin master
From https://vcs.jd-staging.com/bitbucket/scm/bmsg/bmsg
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

Upvotes: 0

Views: 1723

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522762

Most likely a simple git pull would resolve this issue:

# from master
git pull origin master

But note that this may result in merge conflicts locally, which you would have to resolve (followed by a git commit). Another option here would be to pull using a rebase strategy:

git pull --rebase origin master

This would preserve your local commits, though it could still result in merge conflicts happening.

Edit:

The error message refusing to merge unrelated histories means that your local repo is not the same as the remote repo. That is, your local repository contains some project other than what is in the remote to which you are pointing. This could happen because the remote history were changed, or because you configured wrongly locally.

Upvotes: 2

Related Questions