Help Center/ CodeArts Repo/ FAQs/ Merge Request/ Error "failed to push some refs to '....git'" Is Reported When the Merge Request Is Committed Locally
Updated on 2024-11-14 GMT+08:00

Error "failed to push some refs to '....git'" Is Reported When the Merge Request Is Committed Locally

Symptom

If two people modify the same line of code simultaneously, a code commit conflict may arise when the code is pushed to CodeArts Repo. As a result, the push fails and an error message "failed to push some refs to '....git'" is displayed, as shown in the following figure.

Figure 1 Error message displayed when pushing code

Analysis

A conflict occurs when the same line of the same file is modified (the current version of the local repository is different from that of the CodeArts Repo).

Solution

To resolve a code commit conflict, pull the remote repository to the working directory in the local repository. Git will merge the changes and display the conflicting file content that cannot be merged. Then, modify the conflicting content and push it to the remote repository again (by running the add, commit, and push commands in sequence).

Modify the conflicting file carefully. If necessary, negotiate with the other member to resolve the conflict and avoid overwriting the code of other members by mistake.

git pull combines git fetch and git merge. The following describes the operations in detail.

git fetch origin master # Pull the latest content from the master branch of the remote host.
git merge FETCH_HEAD    # Merge the latest content into the current branch.

During merge, a message indicating that the merge fails due to a conflict is displayed.

Resolving Merge Conflicts on the Console

  • Fix them online (recommended for small code volume)
    1. Click Fix them online. A code conflict is displayed, as shown in the following figure.

      On this page, you can directly select the Apply to Source Branch or Apply to Target Branch to select the modification of one party as the final repaired content.

    2. If the situation is complex and the problem cannot be solved by simple direct overwriting, click to enter the manual editing mode, as shown in the following figure.

    3. Manually modify the code to resolve the conflict and commit the changes.

      Enter a commit message.

      In the preceding figure, the following signs are used for conflict display and separation: <<<<, >>>>, and ====. Delete the lines where the signs are located when modifying code.