# Push Options > 原文:[https://docs.gitlab.com/ee/user/project/push_options.html](https://docs.gitlab.com/ee/user/project/push_options.html) * [Push options for GitLab CI/CD](#push-options-for-gitlab-cicd) * [Push options for merge requests](#push-options-for-merge-requests) * [Useful Git aliases](#useful-git-aliases) * [Merge when pipeline succeeds alias](#merge-when-pipeline-succeeds-alias) # Push Options[](#push-options "Permalink") 在 GitLab 11.7 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/15643) . GitLab 支持使用客户端[Git 推送选项](https://git-scm.com/docs/git-push#Documentation/git-push.txt--oltoptiongt)在推送更改的同时执行各种操作. 此外, [推送规则](../../push_rules/push_rules.html)提供服务器端控制和实施选项. 当前,有推送选项可用于: * [Skipping CI jobs](#push-options-for-gitlab-cicd) * [Merge requests](#push-options-for-merge-requests) **注意:** Git 推送选项仅在 Git 2.10 或更高版本中可用. 对于 2.10 至 2.17 版本的 Git,请使用`--push-option` : ``` git push --push-option= ``` 对于 2.18 及更高版本,可以使用以上格式,或更短的`-o` : ``` git push -o ``` ## Push options for GitLab CI/CD[](#push-options-for-gitlab-cicd "Permalink") 您可以使用推入选项跳过 CI / CD 管道或传递环境变量. | 推送选项 | Description | 版本介绍 | | --- | --- | --- | | `ci.skip` | 不要为最新推送创建 CI 管道. | [11.7](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/15643) | | `ci.variable="="` | 如果由于推送而创建了[环境变量](../../ci/variables/README.html) ,请提供要在 CI 管道中使用的[环境变量](../../ci/variables/README.html) . | [12.6](https://gitlab.com/gitlab-org/gitlab/-/issues/27983) | 使用`ci.skip`的示例: ``` git push -o ci.skip ``` An example of passing some environment variables for a pipeline: ``` git push -o ci.variable="MAX_RETRIES=10" -o ci.variable="MAX_TIME=600" ``` ## Push options for merge requests[](#push-options-for-merge-requests "Permalink") 您可以在推送更改的同时使用 Git 推送选项对合并请求执行某些操作: | 推送选项 | Description | 版本介绍 | | --- | --- | --- | | `merge_request.create` | 为推送的分支创建一个新的合并请求. | [11.10](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/26752) | | `merge_request.target=` | 将合并请求的目标设置为特定分支. | [11.10](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/26752) | | `merge_request.merge_when_pipeline_succeeds` | 设置合并请求以[在其管道成功时](merge_requests/merge_when_pipeline_succeeds.html)进行[合并](merge_requests/merge_when_pipeline_succeeds.html) . | [11.10](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/26752) | | `merge_request.remove_source_branch` | 设置合并请求以在合并时删除源分支. | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) | | `merge_request.title=""` | 设置合并请求的标题. 例如: `git push -o merge_request.title="The title I want"` . | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) | | `merge_request.description="<description>"` | 设置合并请求的描述. 例如: `git push -o merge_request.description="The description I want"` . | [12.2](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64320) | | `merge_request.label="<label>"` | 将标签添加到合并请求. 如果标签不存在,它将被创建. 例如,对于两个标签: `git push -o merge_request.label="label1" -o merge_request.label="label2"` . | [12.3](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31831) | | `merge_request.unlabel="<label>"` | 从合并请求中删除标签. 例如,对于两个标签: `git push -o merge_request.unlabel="label1" -o merge_request.unlabel="label2"` . | [12.3](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31831) | 如果您使用要求文本带有空格的 push 选项,则需要用引号( `"` )括起来.如果没有空格,则可以省略引号.例如: ``` git push -o merge_request.label="Label with spaces" git push -o merge_request.label=Label-with-no-spaces ``` 您可以通过使用多个`-o` (或`--push-option` )标志来组合推送选项以一次完成多个任务. 例如,如果您要创建一个新的合并请求,并定位一个名为`my-target-branch` : ``` git push -o merge_request.create -o merge_request.target=my-target-branch ``` 此外,如果希望合并请求在管道成功后立即合并,则可以执行以下操作: ``` git push -o merge_request.create -o merge_request.target=my-target-branch -o merge_request.merge_when_pipeline_succeeds ``` ## Useful Git aliases[](#useful-git-aliases "Permalink") 如上所示,Git 推送选项可能导致 Git 命令增长很长. 如果您经常使用相同的 push 选项,则创建[Git 别名会](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases)很有用. Git 别名是 Git 的命令行快捷方式,可以大大简化长 Git 命令的使用. ### Merge when pipeline succeeds alias[](#merge-when-pipeline-succeeds-alias "Permalink") 要[在管道成功执行 Git push 选项时](#push-options-for-merge-requests)为[合并](#push-options-for-merge-requests)设置 Git 别名: ``` git config --global alias.mwps "push -o merge_request.create -o merge_request.target=master -o merge_request.merge_when_pipeline_succeeds" ``` 然后,为了在管道成功时快速推送将针对 master 并合并的本地分支: ``` git mwps origin <local-branch-name> ```