MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Gitlab Lab – GitLab Code Section

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 itemPurposeURL path (after project URL)Notes
Merge requestsPropose, review and merge changes between branches/-/merge_requestsAvailable in all tiers; approval rules are Premium+
RepositoryBrowse files, switch branches, edit via Web IDE/-/tree/mainPress . on a file or folder to open the Web IDE
BranchesCreate, delete and filter branches/-/branchesThe default branch is protected by default
CommitsHistory of a branch, commit details and diffs/-/commits/mainFilter by author or message
TagsLightweight or annotated tags marking releases/-/tagsTags can be protected, too
Repository graphVisual graph of commits, branches and merges/-/network/mainRead only
Compare revisionsDiff between two branches, tags or commit SHAs/-/compareCan start a merge request from the result
SnippetsProject-scoped code snippets/-/snippetsVisibility can't exceed the project's visibility
Locked filesList of locked files and directories/-/path_locksPremium and Ultimate only

Lab setup before you start

  1. Create a blank project with Initialize repository with a README selected, so main has at least one commit. Without a commit you can't create branches or tags from the UI.
  2. Make sure you have at least the Developer role. You need Maintainer to change protected branch or protected tag settings.
  3. Add a few files to work with, for example app.sh, config.yaml and an image or .psd file for the file-locking exercise.
  4. If you plan to use the CLI, set up an SSH key or a personal access token with read_repository and write_repository scopes for HTTPS cloning.
  5. 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 Compare tab. 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 main or 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-xyz as the source branch and main as 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 typeHow to create itScopeTier
Default branch file and directory lockOpen the file or folder in the Repository view and select LockBlocks other users from pushing or merging changes to that path on the default branchPremium and Ultimate
Exclusive file lock (Git LFS)git lfs lock <file> on a file tracked as lockableBlocks other users from pushing changes to that file on any branchAll 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 actionEffect
/assign @userAssigns the merge request
/assign_reviewer @userRequests a review from a user
/label ~bug ~frontendAdds labels (they must already exist)
/estimate 2hSets a time estimate
/spend 30mLogs time spent
/draftMarks the merge request as draft so it can't be merged yet
/approveApproves the merge request
/mergeMerges, or sets auto-merge if a pipeline is running

Common errors and fixes

SymptomLikely causeFix
You are not allowed to push code to protected branches on this projectPushing directly to protected mainPush to a feature branch and open a merge request, or ask a Maintainer to adjust Settings → Repository → Protected branches
Merge button disabledMerge conflicts, unresolved threads, a failed or required pipeline, or missing approvalsRead the merge checks panel on the merge request, then resolve conflicts or threads, or rerun the pipeline
Cannot create branch or tag in the UIRepository is emptyCommit a README first
Tag creation failsTag name already exists or the tag pattern is protectedUse a new version number, or get a role allowed to create protected tags
Locked files missing from the menuInstance or namespace is on the Free tierUse Git LFS exclusive locks
Push rejected for a specific fileAnother user holds a lock on that pathRun 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-form or fix/123-null-check.
  • Write commit messages in the imperative mood ("Add greeting") and reference issues with #123 so GitLab links them.
  • Use semantic version tags (v1.0.0) and protect the v* 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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
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.

Related Posts

Gitlab – Complete Details of .gitlab-ci.yml

GitLab builds every pipeline from one entry-point configuration file, .gitlab-ci.yml by default, but that file can pull in any number of other YAML files with the include…

Read More

Gitlab FAQ

GitLab cannot restrict who reads or edits a single file in a repository. Access is granted per project. You can still stop secrets from reaching the repository…

Read More

Git, GitHub, and GitLab Interview Questions: Practical Answers and Command Guide

A practical interview-prep guide covering core Git concepts, essential commands, and common GitHub/GitLab questions. Includes workflow diagrams, comparisons, and troubleshooting checklists.

Read More

GitLab Duo Advanced Practitioner + Certified GitLab Duo (AI) Associate Prep (3 Days)

Duration: 3 days (instructor-led, hands-on)Format: 30% guided instruction & demos, 60% labs, 10% exam-style practiceAudience: Developers, DevOps, Security, QA, PMs, Engineering LeadsAssumed level: Participants already know GitLab…

Read More

GitLab for Practical Pipelines, Secure Delivery, and Faster Releases

Introduction Most teams today want faster releases with fewer mistakes. They also want clear visibility, repeatable pipelines, and a clean way to manage code changes. This is…

Read More

Gitlab Workspace: Step-by-Step Guide

You’re encountering the error: “You can’t create a workspace for this project – No agents available to create workspaces.” This means your project is missing a GitLab…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x