Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

12/07/2024

[git] Add git options to Gitlab pushes

Using git it is possible to specify options during push operations to perform specific actions, for example you can have a successful push autocreate the PR/MR and even set additional flags.

You can do this by adding push-options -o OPTION directly via CLI when pushing or setting them globally in your .gitconfig file.

For example, when using GitLab adding the following options to gitconfig:

[push]
    pushOption = merge_request.create
    pushOption = merge_request.target=main
    pushOption = merge_request.squash
    pushOption = merge_request.merge_when_pipeline_succeeds
    pushOption = merge_request.remove_source_branch
    pushOption = merge_request.title="TODO CHANGE ME"
    pushOption = merge_request.draft

after each push you will:

- automatically create a draft MR
- set target branch main
- set title "TODO CHANGE ME"
- assign it to you (and respect any MR template you have eg for default reviewers) 
- set the flags to squash commits on merge
- set the flag to delete source branch on merge
- enable the automerge when all configured checks (pipeline success, required approvals, etc) pass

This small automation will likely help you speed up your development and help you include the CM concepts in your CICD pipelines

17/10/2019

[git] Define code owners and enforce review checks

Git (both GitHub and Bitbucket) allows you to specify code owners for a particular repository. This allows you to set up checks that require an approval from any valid owner before the PR can be merged, it also is an easy place where to look up people working on the specific project.

To add code owners, simply check in a file named CODEOWNERS that includes owners in the format

filter owner

and remember that the LAST matching filter has precedence. For example:

*         @someuser    @someoneelse
*.java    @anotheruser

means that someuser and someoneelse are requested to review any PR, while anotheruser is requested to review PRs that touch java files.

After this file is checked in, remember to also activate the PR check for your repo!