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 that there are both source codes that need to push and pull. One local repository committed code need to be pushed to the remote repository ( Bitbucket ), two remote committed 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 to push my commits, there are error messages in the Pushing To origin popup dialog window, the error message is: 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. See the ‘Note about fast-forwards’ in ‘git push –help’ for details.

So I follow the instruction in the error message, execute the git pull action by clicking 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. Exiting because of unfinished merge.

Now push or pull action all can not work on the current source code commits, they locked each other, what should I do? As you can see the red line in the above 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 the remote repository ( bitbucket server ) branch, there are two blue points which has been committed and pushed to the bitbucket server by others. So before continue I should merge the code between local and remote repositories.

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

Finally, I find the following 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 the OK button in the popup Confirm Backout dialog to reverse the selected changes.
  3. After the above action, your local repository commits will separate from remote repository commits.
  4. Now you can right-click your last local committed but not pushed code changes, then click Rebase menu item in the popup menu list to rebase your local code branch.
  5. Click the OK button in the Confirm Rebase dialog.
  6. Below is the code after the rebase action.
    code-after-rebase-local-branch
  7. Now you can click the Pull button to get server changes to your local repository and merge, then click the Push button to push your local repository changes to the bitbucket server.
0 0 votes
Article Rating
Subscribe
Notify of
guest

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

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x