-1

I get following error when i try to push the local changes to remote.

>git push origin HEAD:dealerpages
To https://bitbucket.org/xxxxxxxxx.git
 ! [rejected]        HEAD -> dealerpages (non-fast-forward)
error: failed to push some refs to 'https://user@bitbucket.org/xxxxxxxxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Here is my complete graph:(git log --graph --oneline --all --decorate)

GIT log Graph

From master i had created two branches 1. psd_to_html 2. white_bkg. Stopped working with psd_to_html and dev continued with white_bkg branch. Later started new branch called dealerpages from white_bkg however messed few commits. Now how do i merge (origin/request-status) (origin/white_bkg) (origin/dealerpages) branches(showed in image) to dealerpages??

code_seeker
  • 112
  • 2
  • 12

1 Answers1

1

You can see from the graph that the origin/dealer_pages has commits included that aren't included on your dealer_pages branch. Hence, the failure to push the local branch to the remote.

The solution is to pull the latest version of the origin/dealer_pages into your local repository.

To avoid unnecessary merges it makes sense to pull the latest version of the origin/dealer_pages using rebase, which will put your local commits on top of the commits from the remote. You do this using the command

git pull --rebase
gerard
  • 835
  • 11
  • 27
  • I tried as you suggested however i get following error when i try to pull the origin/deaerpages `>git pull --rebase origin/dealerpages fatal: origin/dealerpages does not appear to be a git repository fatal: Could not read from remote repository` – code_seeker Apr 26 '17 at 11:10
  • 1
    @praneeth What you are doing it trying to pull a branch from the remote repository called `origin/dealerpages` which doesn't exist. So first, you want to go to the dealerpages local repository using the command `git checkout dealerpages`. Second, you pull the latest version of the remote repository using the command `git pull origin dealerpages --rebase`. – gerard Apr 26 '17 at 11:17
  • thank you, I could successfully execute the commands you had mentioned. but `git status` shows `Your branch is ahead of 'origin/request-status' by 6 commits.` what should i be doing now ?? – code_seeker Apr 26 '17 at 11:21
  • 1
    @praneeth You merged the request-status branch into the dealer pages branch at commit 9cd7770. That's what's causing the problem now. But presumably, you don't want any of the commits after commit 237284c in the request-status branch. If that's the case you can just reset the local request-status branch to be the same as the remote branch. For details on how to do this see http://stackoverflow.com/questions/1628088/reset-local-repository-branch-to-be-just-like-remote-repository-head – gerard Apr 26 '17 at 11:34
  • Okay, i just followed the link you shared....so you mean just do `git fetch origin` and `git reset --hard origin/request-status` – code_seeker Apr 26 '17 at 11:51
  • @praneeth Correct. But make sure you are on the request-status branch in you local repository. – gerard Apr 26 '17 at 11:57