GitLab/Workflows

= Introduction =

This is an effort to document workflows for using our trial GitLab instance for Wikimedia development. Depending on the result of the consultation, it may evolve into a reference for production use.

See Gerrit to GitLab for pointers on how specific features and tasks translate across systems.

= Registering an account on gitlab-test =

Accounts on the test instance are not currently tied to Wikimedia developer accounts. Visit gitlab-test.wmcloud.org/users/sign_in to register.

Note that administrative approval may be required for new accounts, until a test environment is available which integrates with Wikimedia developer accounts.

Add an SSH key
Visit the SSH settings in your profile and add a public key. See the GitLab documentation for more details on this process.

= Making a GitLab Merge Request =

Create a branch
Use the convention :

Make your changes
Write some code and save your changes.

Stage and commit your changes
Let's say you've edited the  in. You should be able to see this using :

Stage the file and commit:

You should now be able to see this commit in the log:

Fork the repository


If you don't have developer-level permissions on the project you'd like to contribute to, you'll first need to copy the repository to your own account. This is known as "forking". Visit the repository page, for example gitlab-test.wmcloud.org/mediawiki/core, and click "Fork" in the upper righthand corner.

Next, add a remote for your fork:

If you've done this successfully, it should show up in your remotes:

Push your commit to GitLab
If you have commit access, you can push directly to a branch on the origin with.

If you're using a fork, push instead to the remote you added above with.

Create a Merge Request on GitLab
You may notice that GitLab responded to the push with a link to create a new merge request from your branch. You can follow that link directly, or visit the trial GitLab instance, navigate to the branch list for the repository, and click the "Merge request" button in the listing.



Provide an informative title and description for the merge request, and @-mention the users you'd like to see review your code. You should be able to use the full range of syntax in GitLab Markdown.

Merge options
In the "Merge options" section:


 * Check "Delete source branch when merge request is accepted" to avoid cluttering the repository with already-merged feature branches. (This is probably the default.)
 * In the general case, you should use "Squash commits when merge request is accepted". (This is probably the default.)
 * This can be omitted if you plan to submit a merge request containing multiple commits.
 * If the logical structure of your change dictates multiple commits, you may use interactive rebase to achieve the desired history and force push to your work branch before merge. This is an advanced workflow, but supported.
 * Check "Allow commits from members who can merge to the target branch", unless you have a specific reason to prevent others from making changes.

Draft / WIP merge requests
If you want to let reviewers know that your change is a work in progress and prevent accidental merges, you can use a draft merge request. Prefix your merge request title with. This will display a notice and disable "merge" button for reviewers.

Making new commits
Typically, you'll just make a new commit on your work branch, as usual, and push to the correct remote:

Or:

The new commit makes it very easy for reviewers to see what changed since they last saw the merge request, and will be squashed into the other commits when the pull request is merged, assuming that the pull request is set up to squash commits on merge (as recommended above).

Force pushing to a branch
If, instead, you wish to rewrite the history of the branch, for example by altering an existing commit or rebasing your work on top of upstream changes, GitLab allows force-pushing to a branch that's associated with a merge request.

This is mainly suitable for merge requests which are not meant to be squashed on merge, typically because they contain two or more commits that should remain separate. In that case, you clean up the history locally and then force-push it to update the merge request.

Getting code review
Once you've submitted a merge request, someone will need to review it. In addition to @-mentioning appropriate users in your merge request description or comments, you can assign a single reviewer. Do this by clicking "Edit" on "Assignees" in the sidebar at the right side of the page when viewing a merge request.

Please see Code review for documentation on reviewing code.

Sources and further reading
There's a lot of quality documentation available for GitLab, although navigating it can be a bit tricky.


 * Contributors to the talk page for the GitLab consultation have reported on various workflow experiments.
 * GitLab User Docs
 * Getting started with merge requests
 * How to create a merge request
 * KDE's GitLab documentation - we're borrowing the convention of work branches from this, and it's a well-written document overall.
 * This document is inspired by and borrows structure from Gerrit/Tutorial.
 * GitLab/Gerrit to GitLab documents how features / concepts map between systems.