DEV Community

Cover image for Create Gitlab PR Template
Sushil Subedi
Sushil Subedi

Posted on • Updated on

Create Gitlab PR Template

For any company projects or gitlab repository we need to make sure all the processes to contribute should be standardized. So, Maintaining a proper pull request standard is an important way. It will save time, energy for you and your team members.
It also helps new team members be able to show the standard and easily onboard themselves to the team.
The best part of creating a Pull Request (Merge Request) template in Gitlab is we can update it anytime and it can be configured in just 5 steps.

Steps to create a PR template in Gitlab:

1.Create a folder .gitlab/merge_request_templates in your project root:
Navigate to your project root and create a folder name as .gitlab then we also need to add another folder inside the .gitlab as merge_request_templates.

gitlab PR template

NOTE: We need to create a .md file and name of the file should be same name of the template you want it to appear in your gitlab repository which we will see visually in the step yet to come.

We can see that I have created a file name called default.md because I want to have a template name as default.

2.Update default.md:
Now, let's update the content inside the default.md as below.

  ## Trello Card Link:

  - Link of a Trello card (we use [Trello] 
    (https://trello.com) for Project Management)  which was assigned for completing the feature.


 ## Tasks Done: (list of tasks completed)

  - What did you complete in this PR? Mention a list of them (we will see it in an example in upcoming steps below on how it is done in a real project)

 ## Tasks Remaining: (List of tasks remaining to be 
    implemented)

 - What is remaining to be implemented in this PR? Mention a 
   list of them 

 ## Steps to test feature:
 - How can we test the feature we implemented in this PR? You 
  could mentioned steps to test it.

 ## Screenshots:

  (if your changes has any UI updates, include screenshot of 
  the changes)

Enter fullscreen mode Exit fullscreen mode

As I want my fellow developers to add trello card link assigned to them, add what they have completed, remaining, how can we test it and screenshots if possible.
This is the template format we use in Truemark Technology which helps the the person who is reviewing the PR know what feature they should be reviewing, link to feature description if they have any confusions and what feature is implement in this PR.

3.Commit and push:
Let's commit the code and push the change to our default branch which in our case is develop.

 > git add .
 > git commit -m "create new template"
 create new template
  1 file changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 .gitlab/merge_request_templates/default.md
> git push origin develop
  Enumerating objects: 6, done.
  Counting objects: 100% (6/6), done.
  Delta compression using up to 8 threads
  Compressing objects: 100% (3/3), done.
  Writing objects: 100% (5/5), 384 bytes | 384.00 KiB/s, done.
  Total 5 (delta 1), reused 0 (delta 0), pack-reused 0
  remote: 
  remote: To create a merge request for develop, visit:
  remote: https://gitlab.com/sushilsubedi151/template- 
          react/-/merge_requests/new? 
          merge_request%5Bsource_branch%5D=develop
remote: 
To gitlab.com:sushilsubedi151/template-react.git
Enter fullscreen mode Exit fullscreen mode

4.Create a new branch to verify new template:
Let's follow below steps to verify new template:

  • Checkout to a branch called check-template with
 git checkout -b check-template
Enter fullscreen mode Exit fullscreen mode
  • Create a dummy file called test.txt and add some content to it with
echo "This is a test content for checking my new PR template in Gitlab" >> test.txt
Enter fullscreen mode Exit fullscreen mode
  • Add new changes with git add . and commit those changes with
git commit -m "Added test.txt to test PR template in Gitlab"
Enter fullscreen mode Exit fullscreen mode
  • Push your changes with
git push origin check-template
Enter fullscreen mode Exit fullscreen mode

5.Create a merge request:
In this step we will breakdown the process into two smaller steps:

  • Choose a template:. Let's create a merge request and set the target branch to develop branch.

Note: Make sure we have set default branch as develop.

To set the default branch from master to develop, we need to follow below steps:
select repository from settings

  • Let's select Repository from Settings as shown above.
    select the develop as default branch

  • Now, Let's select develop from the list of branches and click on Save Changes.

We need to create a merge request by selecting Merge Requests and click on New Merge Request.After, that we need select from the template list.

pr template list

As we can see, default as our template name.

  • Edit the template: In this step, we will be update the selected template. update the pr template

In my case, I have just updated the content of test.so, I have remove Steps to test feature, Screenshots and updated Task completed and remaining task. After this click over Create Merge Request.
create a PR
✅ we have successfully create a merge request using our template.🎉🎉🎉

Conclusion:
I hope this article help to create a standard format for your team. Thank you so much for reading my blog! I really appreciate it!👏

Top comments (0)