debian-mirror-gitlab/doc/user/project/merge_requests/allow_collaboration.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
4.3 KiB
Markdown
Raw Normal View History

2019-09-04 21:01:54 +05:30
---
2020-10-24 23:57:45 +05:30
stage: Create
2021-04-17 20:07:23 +05:30
group: Code Review
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2019-09-04 21:01:54 +05:30
---
2022-03-02 08:16:31 +05:30
# Collaborate on merge requests across forks **(FREE)**
2018-11-08 19:23:39 +05:30
2022-03-02 08:16:31 +05:30
When you open a merge request from your fork, you can allow upstream
members to collaborate with you on your branch.
When you enable this option, members who have permission to merge to the target branch get
permission to write to the merge request's source branch.
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
The members of the upstream project can then make small fixes or rebase branches
before merging.
2018-11-08 19:23:39 +05:30
This feature is available for merge requests across forked projects that are
2019-03-02 22:35:43 +05:30
publicly accessible.
2018-11-08 19:23:39 +05:30
2022-03-02 08:16:31 +05:30
## Allow commits from upstream members
2018-11-08 19:23:39 +05:30
2022-03-02 08:16:31 +05:30
> Enabled by default in [GitLab 13.7 and later](https://gitlab.com/gitlab-org/gitlab/-/issues/23308).
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
As the author of a merge request, you can allow commit edits from
upstream members of the project you're contributing to:
2019-03-02 22:35:43 +05:30
2021-09-04 01:27:46 +05:30
1. While creating or editing a merge request, scroll to **Contribution** and
2022-03-02 08:16:31 +05:30
select the **Allow commits from members who can merge to the target branch**
2021-09-04 01:27:46 +05:30
checkbox.
1. Finish creating your merge request.
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
After you create the merge request, the merge request widget displays the message
**Members who can merge are allowed to add commits**. Upstream members can then
commit directly to your branch, as well as retry the pipelines and jobs of the
merge request.
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
## Prevent commits from upstream members
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
As the author of a merge request, you can prevent commit edits from
upstream members of the project you're contributing to:
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
1. While creating or editing a merge request, scroll to **Contribution** and
clear the **Allow commits from members who can merge to the target branch**
checkbox.
1. Finish creating your merge request.
## Push to the fork as the upstream member
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
You can push directly to the branch of the forked repository if:
2019-03-02 22:35:43 +05:30
2022-03-02 08:16:31 +05:30
- The author of the merge request has enabled contributions from upstream
members.
2022-04-04 11:22:00 +05:30
- You have at least the Developer role in the
2022-03-02 08:16:31 +05:30
upstream project.
In the following example:
- The forked repository URL is `git@gitlab.com:contributor/forked-project.git`.
- The branch of the merge request is `fork-branch`.
To change or add a commit to the contributor's merge request:
2019-03-02 22:35:43 +05:30
2021-09-04 01:27:46 +05:30
1. Open the merge request page, and select the **Overview** tab.
2022-03-02 08:16:31 +05:30
1. Scroll to the merge request widget, and select **Check out branch**.
1. In the modal window, select **Copy** (**{copy-to-clipboard}**).
1. In your terminal, navigate to your cloned version of the repository, and
paste the commands. For example:
2019-03-02 22:35:43 +05:30
2020-03-13 15:44:24 +05:30
```shell
2022-03-02 08:16:31 +05:30
git fetch "git@gitlab.com:contributor/forked-project.git" 'fork-branch'
git checkout -b contributor/fork-branch' FETCH_HEAD
2019-03-02 22:35:43 +05:30
```
2022-03-02 08:16:31 +05:30
Those commands fetch the branch from the forked project, and create a local branch
for you to work on.
1. Make your changes to your local copy of the branch, and then commit them.
1. Push your local changes to the forked project. The following command pushes
the local branch `contributor/fork-branch` to the `fork-branch` branch of
the `git@gitlab.com:contributor/forked-project.git` repository:
2018-11-08 19:23:39 +05:30
2022-03-02 08:16:31 +05:30
```shell
git push git@gitlab.com:contributor/forked-project.git contributor/fork-branch:fork-branch
```
If you have amended or squashed any commits, you must force push. Proceed
with caution as this command rewrites the commit history:
2018-11-08 19:23:39 +05:30
2020-03-13 15:44:24 +05:30
```shell
2022-03-02 08:16:31 +05:30
git push --force git@gitlab.com:contributor/forked-project.git contributor/fork-branch:fork-branch
2019-03-02 22:35:43 +05:30
```
2018-11-08 19:23:39 +05:30
2022-03-02 08:16:31 +05:30
Note the colon (`:`) between the two branches. The general scheme is:
```shell
git push <forked_repository_git_url> <local_branch>:<fork_branch>
```
2019-09-04 21:01:54 +05:30
2021-03-11 19:13:27 +05:30
## Troubleshooting
### Pipeline status unavailable from MR page of forked project
2021-09-04 01:27:46 +05:30
When a user forks a project, the permissions of the forked copy are not copied
2021-03-11 19:13:27 +05:30
from the original project. The creator of the fork must grant permissions to the
forked copy before members in the upstream project can view or merge the changes
in the merge request.
2019-09-04 21:01:54 +05:30
2021-03-11 19:13:27 +05:30
To see the pipeline status from the merge request page of a forked project
going back to the original project:
1. Create a group containing all the upstream members.
2021-09-04 01:27:46 +05:30
1. Go to the **Project information > Members** page in the forked project and invite the newly-created
2021-03-11 19:13:27 +05:30
group to the forked project.