2019-08-08 13:15:27 -04:00
---
2020-07-28 14:09:36 -04:00
stage: Create
group: Source Code
2020-11-26 01:09:20 -05:00
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-08-08 13:15:27 -04:00
type: reference, concepts
---
2019-10-03 11:07:07 -04:00
# Merge Request dependencies **(PREMIUM)**
2019-08-08 13:15:27 -04:00
2020-05-21 23:08:28 -04:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/9688) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.2.
2020-02-11 22:08:55 -05:00
> - [Renamed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/17291) from "Cross-project dependencies" to "Merge Requests dependencies" in [GitLab Premium](https://about.gitlab.com/pricing/) 12.4.
> - Intra-project MR dependencies were [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/16799) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.4.
2019-08-08 13:15:27 -04:00
2019-10-03 11:07:07 -04:00
Merge request dependencies allows a required order of merging
between merge requests to be expressed. If a merge request "depends on" another,
then it cannot be merged until its dependency is itself merged.
2019-08-08 13:15:27 -04:00
2020-12-04 16:09:29 -05:00
NOTE:
2019-08-08 13:15:27 -04:00
Merge requests dependencies are a **PREMIUM** feature, but this restriction is
only enforced for the dependent merge request. A merge request in a **CORE** or
**STARTER** project can be a dependency of a **PREMIUM** merge request, but not
vice-versa.
## Use cases
2019-08-12 00:23:01 -04:00
- Ensure changes to a library are merged before changes to a project that
2019-08-18 20:39:11 -04:00
imports the library.
2019-08-12 00:23:01 -04:00
- Prevent a documentation-only merge request from being merged before the merge request
2019-08-18 20:39:11 -04:00
implementing the feature to be documented.
2019-08-12 00:23:01 -04:00
- Require an merge request updating a permissions matrix to be merged before merging an
2019-08-18 20:39:11 -04:00
merge request from someone who hasn't yet been granted permissions.
2019-08-08 13:15:27 -04:00
It is common for a single logical change to span several merge requests, spread
out across multiple projects, and the order in which they are merged can be
significant.
For example, given a project `mycorp/awesome-project` that imports a library
at `myfriend/awesome-lib` , adding a feature in `awesome-project` may **also**
require changes to `awesome-lib` , and so necessitate two merge requests. Merging
the `awesome-project` merge request before the `awesome-lib` one would
break the `master` branch.
The `awesome-project` merge request could be [marked as
2020-07-16 14:09:35 -04:00
**Draft**](work_in_progress_merge_requests.md),
and the reason for the draft stated included in the comments. However, this
2019-08-08 13:15:27 -04:00
requires the state of the `awesome-lib` merge request to be manually
tracked, and doesn't scale well if the `awesome-project` merge request
depends on changes to **several** other projects.
By making the `awesome-project` merge request depend on the
`awesome-lib` merge request instead, this relationship is
2020-07-16 14:09:35 -04:00
automatically tracked by GitLab, and the draft state can be used to
2019-08-08 13:15:27 -04:00
communicate the readiness of the code in each individual merge request
instead.
## Configuration
To continue the above example, you can configure a dependency when creating the
new merge request in `awesome-project` (or by editing it, if it already exists).
The dependency needs to be configured on the **dependent** merge
2019-10-03 11:07:07 -04:00
request. There is a **Merge request dependencies** section in the form:
2019-08-08 13:15:27 -04:00
2019-10-03 11:07:07 -04:00
![Merge request dependencies form control ](img/dependencies_edit_v12_4.png )
2019-08-08 13:15:27 -04:00
Anyone who can edit a merge request can change the list of dependencies.
New dependencies can be added by reference, or by URL. To remove a dependency,
2019-08-18 20:39:11 -04:00
press the **X** by its reference.
2019-08-08 13:15:27 -04:00
2019-10-03 11:07:07 -04:00
As dependencies can be specified across projects, it's possible that someone else
2019-08-08 13:15:27 -04:00
has added a dependency for a merge request in a project you don't have access to.
These are shown as a simple count:
2019-10-03 11:07:07 -04:00
![Merge request dependencies form control with inaccessible merge requests ](img/dependencies_edit_inaccessible_v12_4.png )
2019-08-08 13:15:27 -04:00
2019-08-18 20:39:11 -04:00
If necessary, you can remove all the dependencies like this by pressing the
**X**, just as you would for a single, visible dependency.
2019-08-08 13:15:27 -04:00
2019-08-18 20:39:11 -04:00
Once you're finished, press the **Save changes** button to submit the request,
or **Cancel** to return without making any changes.
2019-08-08 13:15:27 -04:00
The list of configured dependencies, and the status of each one, is shown in the
merge request widget:
2019-10-03 11:07:07 -04:00
![Dependencies in merge request widget ](img/dependencies_view_v12_2.png )
2019-08-08 13:15:27 -04:00
2019-08-18 20:39:11 -04:00
Until all dependencies have, themselves, been merged, the **Merge**
2019-08-08 13:15:27 -04:00
button will be disabled for the dependent merge request. In
2019-08-18 20:39:11 -04:00
particular, note that **closed merge requests** still prevent their
2019-08-08 13:15:27 -04:00
dependents from being merged - it is impossible to automatically
determine whether the dependency expressed by a closed merge request
has been satisfied in some other way or not.
If a merge request has been closed **and** the dependency is no longer relevant,
it must be removed as a dependency, following the instructions above, before
merge.
## Limitations
2020-05-21 23:08:28 -04:00
- API support: [issue #12551 ](https://gitlab.com/gitlab-org/gitlab/-/issues/12551 )
- Dependencies are not preserved across project export/import: [issue #12549 ](https://gitlab.com/gitlab-org/gitlab/-/issues/12549 )
- Complex merge order dependencies are not supported: [issue #11393 ](https://gitlab.com/gitlab-org/gitlab/-/issues/11393 )
2019-08-08 13:15:27 -04:00
The last item merits a little more explanation. Dependencies between merge
requests can be described as a graph of relationships. The simplest possible
graph has one merge request that depends upon another:
```mermaid
graph LR;
myfriend/awesome-lib!10-->mycorp/awesome-project!100;
```
A more complex (and still supported) graph might have one merge request that
directly depends upon several others:
```mermaid
graph LR;
myfriend/awesome-lib!10-->mycorp/awesome-project!100;
herfriend/another-lib!1-->mycorp/awesome-project!100;
```
Several different merge requests can also directly depend upon the
same merge request:
```mermaid
graph LR;
herfriend/another-lib!1-->myfriend/awesome-lib!10;
herfriend/another-lib!1-->mycorp/awesome-project!100;
```
2020-02-11 22:08:55 -05:00
What is **not** supported is a "deep", or "nested" graph of dependencies. For example:
2019-08-08 13:15:27 -04:00
```mermaid
graph LR;
herfriend/another-lib!1-->myfriend/awesome-lib!10;
myfriend/awesome-lib!10-->mycorp/awesome-project!100;
```
In this example, `myfriend/awesome-lib!10` depends on `herfriend/another-lib!1` ,
and is itself a dependent of `mycorp/awesome-project!100` . This means that
`myfriend/awesome-lib!10` becomes an **indirect** dependency of
`mycorp/awesome-project!100` , which is not yet supported.