<p>No. The advantage to <code>!reference</code> compared to &quot;YAML Anchors&quot; is that <a href="https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html#reference-tags" rel="nofollow noreferrer">it works over foreign yaml <code>include</code></a>,</p>
<blockquote>
<p>You can’t use YAML anchors across multiple files when using the <code>include</code> keyword. Anchors are only valid in the file they were defined in. To reuse configuration from different YAML files, use !reference tags or the extends keyword.</p>
</blockquote>
<p>However, GitHub doesn't have YAML Anchors either. But <a href="https://github.com/actions/runner/issues/1182" rel="nofollow noreferrer">there is a feature request for that.</a></p>

CC BY-SA 4.0
2024-11-08T21:48:11.053Z
2024-11-08T21:48:11.053Z
Evan Carroll
<p>Does GitHub support anything that allows you to create snippets like GitLab's <code>!reference</code>? I'm looking to reduce code duplication in a workflow?</p>

<yaml><github-actions>
Does GitHub support anything like GitLab's !reference (or YAML Anchors)?
Evan Carroll
# Does GitHub support anything like GitLab's !reference (or YAML Anchors)?

(Asked by: username_0 on 2024-11-08)

Does GitHub support anything that allows you to create snippets like GitLab's `!reference`? I'm looking to reduce code duplication in a workflow?

**Tags:** yaml, github-actions


---

## 1 answers

### Answer by username_0 on 2024-11-08. Score: 0

No. The advantage to `!reference` compared to "YAML Anchors" is that [it works over foreign yaml `include`](https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html#reference-tags),

> You can’t use YAML anchors across multiple files when using the `include` keyword. Anchors are only valid in the file they were defined in. To reuse configuration from different YAML files, use !reference tags or the extends keyword.

However, GitHub doesn't have YAML Anchors either. But [there is a feature request for that.](https://github.com/actions/runner/issues/1182)


---

