This lab walks through every item under the Code menu of a GitLab project: repository browsing, branches, commits, tags, merge requests, the repository graph, compare revisions, snippets and locked files. Below the lab manual you will find the matching Git commands, fixes to a few steps that don't match how GitLab works, how file locking really works, and fixes for errors students often hit.
What each item in the Code menu does
In current GitLab versions the project's left sidebar groups source-control features under Code. The table maps each menu item to its purpose and the URL path it opens, which helps when the UI moves things around between releases.
| Menu item | Purpose | URL path (after project URL) | Notes |
|---|---|---|---|
| Merge requests | Propose, review and merge changes between branches | /-/merge_requests | Available in all tiers; approval rules are Premium+ |
| Repository | Browse files, switch branches, edit via Web IDE | /-/tree/main | Press . on a file or folder to open the Web IDE |
| Branches | Create, delete and filter branches | /-/branches | The default branch is protected by default |
| Commits | History of a branch, commit details and diffs | /-/commits/main | Filter by author or message |
| Tags | Lightweight or annotated tags marking releases | /-/tags | Tags can be protected, too |
| Repository graph | Visual graph of commits, branches and merges | /-/network/main | Read only |
| Compare revisions | Diff between two branches, tags or commit SHAs | /-/compare | Can start a merge request from the result |
| Snippets | Project-scoped code snippets | /-/snippets | Visibility can't exceed the project's visibility |
| Locked files | List of locked files and directories | /-/path_locks | Premium and Ultimate only |
Lab setup before you start
- Create a blank project with Initialize repository with a README selected, so
mainhas at least one commit. Without a commit you can't create branches or tags from the UI. - Make sure you have at least the Developer role. You need Maintainer to change protected branch or protected tag settings.
- Add a few files to work with, for example
app.sh,config.yamland an image or.psdfile for the file-locking exercise. - If you plan to use the CLI, set up an SSH key or a personal access token with
read_repositoryandwrite_repositoryscopes for HTTPS cloning. - Invite a second user (or a classmate) as Developer so you can practise assigning reviewers and approving merge requests.
Note: The main branch is protected by default. Developers can usually merge into it through a merge request but cannot push to it directly. This is intended, and it's why the lab uses a feature branch.
The same lab from the command line
Most teams work locally and use the GitLab UI for review. These commands cover the same steps as sections 2 to 7 above. Replace the clone URL with your project's URL.
# Clone and create the feature branch
git clone git@gitlab.com:<namespace>/<project>.git
cd <project>
git switch -c feature-xyz
# Make and commit a change
echo 'echo "hello from feature-xyz"' >> app.sh
git add app.sh
git commit -m "Add greeting to app.sh"
# Push the branch and open a merge request in one step
git push -u origin feature-xyz \
-o merge_request.create \
-o merge_request.target=main \
-o merge_request.title="Add greeting to app.sh"
# Inspect history locally (similar to Commits and Repository graph)
git log --oneline --graph --all
# Compare branches (similar to Compare revisions)
git fetch origin
git diff origin/main...origin/feature-xyz --stat
# After the MR is merged, tag the release on main
git switch main
git pull
git tag -a v1.0.0 -m "First release"
git push origin v1.0.0Code language: HTML, XML (xml)
The -o merge_request.* push options tell GitLab to create the merge request while the push is processed, and the response includes a link to it. git tag -a creates an annotated tag, which stores the tagger and a message. GitLab release pages and most versioning tools work best with annotated tags.
Corrections and clarifications to the lab steps
- Commits, step 4: the Commits page has no
Comparetab. To compare two commits, use Code → Compare revisions and paste the two commit SHAs into the source and target fields. - Tags, step 3: in the New tag form, set Create from to
mainor to a specific commit SHA. If you fill in Message, GitLab creates an annotated tag. If you leave it empty, you get a lightweight tag. - Merge requests, step 2: pick
feature-xyzas the source branch andmainas the target branch, then select Compare branches and continue. If the branch was pushed recently, the banner on the project page offers a quicker Create merge request button. - Merge requests, step 6: on the Free tier anyone eligible can approve, but approvals are not required before merging. Required approval rules need Premium or Ultimate.
- Snippets, step 4: a project snippet can't be more visible than its project. On GitLab.com, Internal visibility is not available for new snippets, so choose Private or Public.
- Locked files: the Locked files page only lists existing locks. You lock a file from the file view itself, and the lock blocks changes from other users instead of making the file editable only by you. The next section covers the details.
- Repository: the main file browser is Code → Repository. Single-file edits use Edit → Edit single file, and multi-file edits use Edit → Web IDE.
How file locking actually works
GitLab offers two kinds of lock, and they behave differently:
| Lock type | How to create it | Scope | Tier |
|---|---|---|---|
| Default branch file and directory lock | Open the file or folder in the Repository view and select Lock | Blocks other users from pushing or merging changes to that path on the default branch | Premium and Ultimate |
| Exclusive file lock (Git LFS) | git lfs lock <file> on a file tracked as lockable | Blocks other users from pushing changes to that file on any branch | All tiers, requires Git LFS |
For binary files such as logo.psd, Git LFS locking is the better fit because it works on every branch and from the command line:
git lfs install
git lfs track "*.psd" --lockable
git add .gitattributes logo.psd
git commit -m "Track PSD files with LFS as lockable"
git push
git lfs lock logo.psd # take the lock
git lfs locks # list current locks
git lfs unlock logo.psd # release it when doneCode language: PHP (php)
Note: Files marked --lockable are checked out as read-only until you lock them. This reminds everyone to take the lock before editing. Maintainers can remove another user's lock with git lfs unlock --force or from the Locked files page.
Useful quick actions in merge requests
Quick actions go on their own line in a merge request description or comment. GitLab runs them when the comment is posted. The bonus tips above mention three of them. These ones also come up often in this lab:
| Quick action | Effect |
|---|---|
/assign @user | Assigns the merge request |
/assign_reviewer @user | Requests a review from a user |
/label ~bug ~frontend | Adds labels (they must already exist) |
/estimate 2h | Sets a time estimate |
/spend 30m | Logs time spent |
/draft | Marks the merge request as draft so it can't be merged yet |
/approve | Approves the merge request |
/merge | Merges, or sets auto-merge if a pipeline is running |
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
You are not allowed to push code to protected branches on this project | Pushing directly to protected main | Push to a feature branch and open a merge request, or ask a Maintainer to adjust Settings → Repository → Protected branches |
| Merge button disabled | Merge conflicts, unresolved threads, a failed or required pipeline, or missing approvals | Read the merge checks panel on the merge request, then resolve conflicts or threads, or rerun the pipeline |
| Cannot create branch or tag in the UI | Repository is empty | Commit a README first |
| Tag creation fails | Tag name already exists or the tag pattern is protected | Use a new version number, or get a role allowed to create protected tags |
| Locked files missing from the menu | Instance or namespace is on the Free tier | Use Git LFS exclusive locks |
| Push rejected for a specific file | Another user holds a lock on that path | Run git lfs locks or check the Locked files page, then ask the owner to unlock |
Good habits to take from this lab
- Keep branches short-lived and name them after the work, such as
feature/login-formorfix/123-null-check. - Write commit messages in the imperative mood ("Add greeting") and reference issues with
#123so GitLab links them. - Use semantic version tags (
v1.0.0) and protect thev*pattern so only Maintainers can create release tags. - Turn on Delete source branch when merging so stale branches don't pile up.
- Never store secrets in snippets, even private ones. Use CI/CD variables instead. To continue into pipelines, see What is GitLab CI/CD and use cases of GitLab CI/CD?.
Frequently asked questions
Where is the Repository graph in the new GitLab navigation?
Open the project and go to Code → Repository graph in the left sidebar. You can also add /-/network/<branch> to the project URL.
Why can't I see Locked files in my GitLab project?
Locking files and directories from the UI is a Premium and Ultimate feature, so the menu item is hidden on the Free tier. Free-tier users can still lock files with Git LFS by running git lfs lock.
What is the difference between a lightweight and an annotated tag in GitLab?
A lightweight tag is just a pointer to a commit. An annotated tag also stores the tagger, a date and a message. In the GitLab New tag form, filling in the Message field creates an annotated tag.
Can I create a merge request without opening the GitLab UI?
Yes. Push with git push -o merge_request.create -o merge_request.target=main, and GitLab creates the merge request and returns its link in the push output.
Why can't I push to main in my GitLab project?
The default branch is protected, and by default Developers cannot push to it directly. Push to a feature branch and merge through a merge request, or ask a Maintainer to change the protected branch settings.
Related tutorials
- Gitlab Lab – Plan – Step-by-Step Tutorial: GitLab Cloud
- What is GitLab CI/CD and use cases of GitLab CI/CD?
- GitLab Hierarchy: Organization, Namespace, Group & Project
- More GitLab tutorials
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals