GitLab Fundamentals - Hands-On Lab: Repository Management and Branching
Estimated time to complete: 15 minutes
Objectives
In this lab, we will explore how we can create repositories to organize code, as well as configure the repositories to meet various use cases.
Task A. Configuring your project
In the left sidebar, you will see a few new options available when you are in your project.
-
Navigate to your Cool App QA project.
-
In the left sidebar, select Settings. From the resulting dropdown, select General.
-
Review the different settings available in general. Here you can toggle your project visibility, features enabled, as well as advanced options like moving and deleting projects.
-
In the left sidebar, under Settings, select Repository. This section contains configurations for your project code repository.
In most settings, you will want to toggle a few settings for your repository. First, you will want to ensure your project has a consistent default branch. This branch will be the branch that merge requests are made against in your project. For this main branch, you will want to ensure it is protected and not able to be pushed directly to. Let’s look at how to configure these options.
-
In Repository Settings, select Branch defaults to expand this section.
Here, you will see that
main
is your default branch. -
Next, select Branch rules.
-
Beside the
main
rules, select View details. -
Explore the settings available here. You will see that by default,
Allow force push
is disabled for the main branch. You will also see that users with aMaintainer
role can push and merge tomain
. Ideally, we want to prevent anyone from pushing intomain
directly. -
To prevent pushes to main, select Edit in the Allowed to push and merge section.
-
Check the No one checkbox. Select Save changes.
With this setting changed, now no one can directly push to main
. Let’s test this out to see the result.
Task B. Testing pushes to main
-
In the left sidebar, select Code > Repository.
-
At the top of the repository section, select + > New file.
-
In the Filename, enter
test.txt
. -
Enter any text into the file contents.
-
Select Commit changes.
-
In the New branch section, notice that there is a note stating “You don’t have permission to commit to
main
”. This is a direct result of our branch rules. To accommodate the change, this window has automatically created a new branch for us to use. -
In New branch, change the name to
test-commit
. -
Uncheck Create a merge request for this change.
-
Select Commit changes.
After committing the changes, you will now see the file available. This created a new branch in your project. To return to your main branch, select the dropdown that currently says test-commit. From this dropdown, select main to see your main branch again.
Now that we have a change in a branch, we can explore the concept of merge requests to merge the changes into main in the next lab.
Lab Guide Complete
You have completed this lab exercise. You can view the other lab guides for this course.
Suggestions?
If you’d like to suggest changes to the lab, please submit them via merge request.
cc8c3b6e
)