Description
I would like to bring to your attention some problems with the merge conflict resolution instructions provided in Gitea when a pull request has conflicts with the target branch.
Note: For simplicity, I will use master as the target branch in this example. However, the target branch could be any branch, and the issues described apply universally.
Current Instructions:
This pull request has changes conflicting with the target branch.
• src/main/resources/test.properties
You can also view command line instructions.
Step 1: From your project repository, check out a new branch and test the changes.
git checkout -b feature/branch-name master
git pull origin feature/branch-name
Step 2: Merge the changes and update on Gitea.
git checkout master
git merge --no-ff feature/branch-name
git push origin master
Issues Identified:
Step 1 Problem: The command git checkout -b feature/branch-name master attempts to create a new branch named feature/branch-name from master. If feature/branch-name already exists (which is likely in the context of a pull request), this results in an error:
fatal: A branch named 'feature/branch-name' already exists.
Additionally, creating the branch from master may not be appropriate if the feature branch was originally based on a different commit or branch.
Suggested Correction:
git fetch origin
git checkout feature/branch-name
This updates the local repository and switches to the existing feature branch.
Step 2 Problem: The instructions advise switching to master, merging the feature branch into it, and pushing back to master. This workflow bypasses the pull request process and directly modifies the master branch, which is typically not recommended.
In standard practice, especially when working with pull requests, conflicts should be resolved within the feature branch by integrating changes from master into it. This ensures that the feature branch is up-to-date and that the pull request can be merged without issues.
Suggested Correction:
git checkout feature/branch-name
git pull origin master
# Resolve any merge conflicts
git add <resolved-files>
git commit -m "Resolved merge conflicts with master"
git push origin feature/branch-name
Proposed Corrected Instructions:
Step 1: Update your local repository and switch to your feature branch
git fetch origin
git checkout feature/branch-name
Step 2: Integrate the latest changes from master into your feature branch
git pull origin master
Step 3: Resolve any merge conflicts
- Open each conflicted file and resolve the conflicts manually.
- After resolving, stage the changes:
git add <conflicted-files>
git commit -m "Resolved merge conflicts with master"
Step 4: Push the updated feature branch to the remote repository
git push origin feature/branch-name
This approach aligns with common Git workflows and maintains the integrity of the master branch. It allows the pull request to be updated with the conflict resolutions, facilitating a smooth merge once approved.
Screenshots
Gitea Version
1.22.1
Can you reproduce the bug on the Gitea demo site?
No
Operating System
Centos9 Stream
Browser Version
Chrome any