How to Create Groups and Move Projects in GitLab

John Wachira Mar 11, 2025 Git Git GitLab
  1. Creating Groups in GitLab
  2. Moving Projects to a Group
  3. Using GitLab API to Create Groups
  4. Using GitLab API to Move Projects
  5. Conclusion
  6. FAQ
How to Create Groups and Move Projects in GitLab

Creating groups and moving projects in GitLab can significantly enhance your workflow and collaboration efforts. GitLab groups serve as a way to categorize projects, allowing teams to work together more effectively.

In this article, we will explore the steps needed to create groups and move projects within GitLab, ensuring that your development process is organized and streamlined. Whether you are a seasoned developer or new to GitLab, understanding these functionalities will help you manage your projects more efficiently. Let’s dive into the details!

Creating Groups in GitLab

Creating a group in GitLab is a straightforward process that helps you organize your projects. Groups act as containers for your repositories, allowing you to manage permissions and visibility settings more effectively. Here’s how you can create a group:

  1. Log in to your GitLab account.
  2. On the top navigation bar, click on the “Groups” dropdown.
  3. Select “Your groups” and then click on the “New group” button.
  4. Fill in the required details, including the group name, path, and visibility level (private, internal, or public).
  5. Click on “Create group.”

Once the group is created, you can add members and set their permissions. This way, everyone involved in the project can access the necessary resources while maintaining security.

Moving Projects to a Group

After creating a group, you may want to move existing projects into it for better organization. Moving projects in GitLab is simple and can be done through the project settings. Here’s a step-by-step guide:

  1. Navigate to the project you wish to move.
  2. Go to “Settings” in the left sidebar.
  3. Click on “General.”
  4. Scroll down to the “Advanced” section.
  5. Look for the “Transfer project” option and click on it.
  6. Select the target group from the dropdown menu.
  7. Confirm the transfer by typing the project name and clicking “Transfer project.”

This process allows you to keep your projects neatly organized under the appropriate group, making collaboration easier for your team.

Using GitLab API to Create Groups

For those who prefer automation or need to create multiple groups, using the GitLab API can be a powerful solution. Below is a Python script that demonstrates how to create a group using the GitLab API.

import requests

url = "https://gitlab.example.com/api/v4/groups"
headers = {
    "Private-Token": "your_access_token"
}
data = {
    "name": "New Group",
    "path": "new-group"
}

response = requests.post(url, headers=headers, json=data)

print(response.status_code)
print(response.json())

Output:

201
{'id': 123, 'name': 'New Group', 'path': 'new-group', ...}

In this script, we define the API endpoint for creating a group and specify the necessary headers, including your personal access token. The data dictionary contains the group name and path. Upon executing the script, a new group will be created, and the response will provide details about the newly created group.

Using GitLab API to Move Projects

Similarly, you can also use the GitLab API to move projects into a group programmatically. Here’s how you can do it with a Python script:

import requests

project_id = 456
group_id = 123
url = f"https://gitlab.example.com/api/v4/projects/{project_id}/transfer"
headers = {
    "Private-Token": "your_access_token"
}
data = {
    "namespace_id": group_id
}

response = requests.post(url, headers=headers, json=data)

print(response.status_code)
print(response.json())

Output:

200
{'id': 456, 'name': 'Project Name', 'namespace': {'id': 123, 'name': 'New Group', ...}}

In this example, we first set the project_id and group_id. The API endpoint for transferring a project is constructed using the project ID. The request includes the new namespace_id, which corresponds to the target group. Upon successful execution, the project will be moved, and the response will confirm the transfer.

Conclusion

In summary, creating groups and moving projects in GitLab is essential for maintaining an organized workflow. Groups provide a structured way to manage projects and facilitate collaboration among team members. By following the steps outlined in this article, you can efficiently create groups and transfer projects, whether through the GitLab interface or using the API. Embrace these functionalities to enhance your GitLab experience and streamline your development process.

FAQ

  1. How do I create a group in GitLab?
    To create a group, log in to GitLab, navigate to the Groups dropdown, select “Your groups,” and click on “New group.” Fill in the required details and click “Create group.”

  2. Can I move multiple projects at once in GitLab?
    No, GitLab does not support moving multiple projects simultaneously through the interface. However, you can automate the process using the GitLab API.

  3. What permissions can I set for group members?
    You can set various permissions for group members, including Guest, Reporter, Developer, Maintainer, and Owner, depending on the level of access you want to grant.

  4. Is it possible to change a group’s visibility after creation?
    Yes, you can change a group’s visibility by navigating to the group’s settings and adjusting the visibility level.

  5. What happens to the project’s history when I move it to a group?
    The project’s history remains intact when you move it to a group. All commits, issues, and merge requests will still be accessible.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git GitLab