0

To mySpace@192.168.169.1:/Repo.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'mySpace@192.168.169.1:/Repo.git'

Hint: Updates were rejected because a pushed branch tip is behind its remote counterpart. Check out this branch and integrate the remote changes (e.g. 'git pull ...') before pushing again. See the 'Note about fast-forwards' in 'git push --help' for details.`

I got this git error every time I am going to git push -u origin master or git push -f origin master. Yes, I am trying push my committed work and I don't want to reset -hard or rebase because I know my committed work will be gone. Please any idea how to push my work successfully.

creyD
  • 1,972
  • 3
  • 26
  • 55
Gray
  • 387
  • 1
  • 4
  • 12
  • Rebase can’t make your commits gone. Run `git pull —rebase` before push. It’s double - before rebase. – ElpieKay Oct 16 '17 at 03:14
  • @ElpieKay okey, I will try it but it fails I'm toast. – Gray Oct 16 '17 at 03:17
  • If your git version is too old to support pull rebase, you could run `git fetch origin master && git rebase FETCH_HEAD`. `git reflog` can tell you which commit you were on if you find any commit is gone. – ElpieKay Oct 16 '17 at 03:21
  • @ElpieKay can you tell how can push the head I selected ? I want my work to be the head. – Gray Oct 16 '17 at 03:43
  • Just fetch, rebase and push. Your commits may be recreated and sha1 will be new, but the changes and the author and the email are kept. Rebase is the cleanest and safest way. – ElpieKay Oct 16 '17 at 03:49
  • 1
    Possible duplicate of [Geting an error pushing to github - Updates were rejected because a pushed branch tip is behind its remote](https://stackoverflow.com/questions/14609263/geting-an-error-pushing-to-github-updates-were-rejected-because-a-pushed-branc) – phd Oct 16 '17 at 05:34
  • Thanks @ElpieKay , I got it but I've added something from https://stackoverflow.com/a/35740070/7555344 , it made me checkout the latest head and sync my committed work. – Gray Oct 16 '17 at 05:46
  • @phd maybe but it didn't help... – Gray Oct 16 '17 at 05:48
  • What have you tried? Tried `git pull --rebase`? – phd Oct 16 '17 at 17:55
  • yes, I've tried it @phd and also I added **git checkout -b ** to make my commit id sync in into the most latest head. – Gray Oct 19 '17 at 03:30

2 Answers2

2

Please try this on a copy of your local repo:

cd /path/to/your/repo/myrepo
git remote -v # take note of that url

cd ..
git clone myrepo myrepo2
cd myrepo2
git remote set-url origin /url/of/your/remote/repo

Finally, try a git pull --rebase

Or:

git fetch
git rebase origin/master
git push

In both instance, if anything goes wrong, you still have your original work in myrepo.

creyD
  • 1,972
  • 3
  • 26
  • 55
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Looks like one of your local branch is behind the remote branch. You need to identify that branch, perform a git pull on it in a seperate branch and then merge that local branch with this new branch. Then perform git push