How to Create a GitLab Project and Assign Roles: Understanding Access Permissions

Ayushmaan Srivastav
3 min readOct 19, 2024

--

In GitLab, different roles define what actions a user can perform within a project. For effective team collaboration, it’s important to assign appropriate roles such as Developer, Maintainer, or Guest, ensuring that everyone has the right level of access. In this blog, we will guide you through creating a GitLab project, assigning different roles to users, and verifying access permissions by performing actions like merging, pushing, and creating issues.

What Are GitLab Roles?

GitLab offers several roles to control the level of access each team member has within a project:

  • Guest: Limited to viewing public information and creating issues.
  • Reporter: Can view and clone repositories but cannot push code.
  • Developer: Can push code, create merge requests, and contribute to the repository.
  • Maintainer: Can manage the repository settings, merge branches, and push to protected branches.
  • Owner: Full control over the project, including administrative settings (only available at the group level).

Assigning the right role ensures that the team members can perform their duties while keeping sensitive actions restricted.

Step 1: Create a GitLab Project

To get started, we need to create a GitLab project where we’ll assign roles.

  1. Log in to GitLab:
  • Go to GitLab and log in using your credentials.

2. Create a New Project:

Click the New Project button on the dashboard.

Choose Create blank project.

Fill in the project details:

  • Project name: Name your project (e.g., Team Collaboration).
  • Visibility level: Set the visibility (Private, Internal, or Public).

Click Create project.

Once created, you’ll be directed to the project’s main page.

Step 2: Add Users and Assign Roles

Now that the project is created, let’s add users and assign them different roles.

  1. Navigate to Project Members:
  • On the left sidebar, go to Project information > Members.

2. Add Members:

  • In the Invite member field, enter the email address or GitLab username of the user you want to add.
  • In the Select a role permission dropdown, choose the role you want to assign (e.g., Developer, Maintainer).
  • Click Invite to send the invitation.

Repeat the process to invite other team members with different roles (e.g., one as a Developer and one as a Maintainer).

Step 4: Verify Access Permissions for Each Role

1. Verify Developer Permissions:

  • As a Developer:
  • The developer should be able to clone the repository by running
git clone https://gitlab.com/your-username/team-collaboration.git

They should also be able to push changes

git add .
git commit -m "Developer changes"
git push origin main
  • They can create merge requests but cannot merge them.

2. Verify Maintainer Permissions:

  • As a Maintainer:
  • The maintainer can merge merge requests. After reviewing the developer’s merge request, they can merge it by clicking the Merge button in the GitLab UI.
  • Maintainers can also push to protected branches, change repository settings, and invite other members.

3. Testing Role Restrictions:

  • Guests and Reporters should not be able to push code or merge requests. They will be able to view the repository and create issues, but attempts to push code will result in permission errors.

Example Scenario:

1.Developer pushes a new feature to a branch:

git checkout -b new-feature
git add .
git commit -m "New feature by Developer"
git push origin new-feature

2. Developer creates a merge request for the feature.

3. Maintainer reviews and merges the request into the main branch.

Conclusion

In this blog, we’ve walked through the steps of creating a GitLab project, assigning different roles to users, and verifying their access permissions by performing actions like pushing and merging. Understanding GitLab roles and permissions ensures that your project is managed securely and efficiently, with the right people having access to the right actions.

--

--

No responses yet