How To Resolve Git Push, Pull, Merge Conflicts In Bitbucket Use SourceTree

When i use SourceTree ( a git client tool ) to manage my source code, i meet a use case which there are both code need to push and pull. One local repository committed code need to be pushed to remote repository ( bitbucket ), two remote code need to be pulled down to local repository as below picture.

local repository has commit but not pushed, but remote repository has two pushed commit ahead

But when i click the Push button, there are error messages : Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g. ‘git pull …’) before pushing again.

when click push button to push local staged files to remote repository

So i follow the instruction in the error message, execute git pull action by click the Pull button. But this time i meet another error message : You have not concluded your merge (MERGE_HEAD exists). Please, commit your changes before merging.

when click pulling button to pull source code from remote repository

Now push or pull action all can not work on current code, they locked each other, what should i do.

As you can see the red line in below picture is my local repository branch, there has one red point which has been committed but not pushed to bitbucket ( remote repository ).

The blue line is remote repository ( bitbucket sever ) branch, there are two blue point which has been committed and pushed to bitbucket server by others.

So before continue i should merge the code between local and remote repository.

local repository has commit but not pushed, but remote repository has two pushed commit ahead

1. How To Merge The Code Between Local And Remote Repository?

Finally i find follow steps to merge local and remote repository code.

  1. Right click the conflict committed changes, then click Reset master to this commit menu item in the popup menu list.
    reset master to this commit menu item
  2. Click OK button in the popup Confirm Backout dialog to reverse the selected changes.
    confirm reverse the selected changes
  3. After above action, you local repository commits will separate from remote repository commits.
    your local repository will separate from remote repository
  4. Now you can right click your last local committed but not pushed code changes, then click Rebase menu item to rebase your local code branch.
    rebase local code branch last commit but not push changes
  5. Click OK button in the confirm rebase dialog.
    confirm rebase dialog
  6. Below is the code after rebase action.
    code after rebase local branch
  7. Now you can click Pull button to get server changes to your local repository and merge, then click Push button to push you local repository changes to bitbucket server.
0 0 vote
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x