{"id":49490,"date":"2026-11-23T22:06:14","date_gmt":"2026-11-23T22:06:14","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=49490"},"modified":"2026-11-23T22:06:14","modified_gmt":"2026-11-23T22:06:14","slug":"gitlab-lab-gitlab-code-section","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/gitlab-lab-gitlab-code-section\/","title":{"rendered":"Gitlab Lab \u2013 GitLab Code Section"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This lab walks through every item under the <strong>Code<\/strong> 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&#039;t match how GitLab works, how file locking really works, and fixes for errors students often hit.<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/8cafc0c90f000a82c1107d2b6614618f.js\"><\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What each item in the Code menu does<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In current GitLab versions the project&#039;s left sidebar groups source-control features under <strong>Code<\/strong>. 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.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Menu item<\/th><th>Purpose<\/th><th>URL path (after project URL)<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>Merge requests<\/td><td>Propose, review and merge changes between branches<\/td><td><code>\/-\/merge_requests<\/code><\/td><td>Available in all tiers; approval rules are Premium+<\/td><\/tr><tr><td>Repository<\/td><td>Browse files, switch branches, edit via Web IDE<\/td><td><code>\/-\/tree\/main<\/code><\/td><td>Press <code>.<\/code> on a file or folder to open the Web IDE<\/td><\/tr><tr><td>Branches<\/td><td>Create, delete and filter branches<\/td><td><code>\/-\/branches<\/code><\/td><td>The default branch is protected by default<\/td><\/tr><tr><td>Commits<\/td><td>History of a branch, commit details and diffs<\/td><td><code>\/-\/commits\/main<\/code><\/td><td>Filter by author or message<\/td><\/tr><tr><td>Tags<\/td><td>Lightweight or annotated tags marking releases<\/td><td><code>\/-\/tags<\/code><\/td><td>Tags can be protected, too<\/td><\/tr><tr><td>Repository graph<\/td><td>Visual graph of commits, branches and merges<\/td><td><code>\/-\/network\/main<\/code><\/td><td>Read only<\/td><\/tr><tr><td>Compare revisions<\/td><td>Diff between two branches, tags or commit SHAs<\/td><td><code>\/-\/compare<\/code><\/td><td>Can start a merge request from the result<\/td><\/tr><tr><td>Snippets<\/td><td>Project-scoped code snippets<\/td><td><code>\/-\/snippets<\/code><\/td><td>Visibility can&#039;t exceed the project&#039;s visibility<\/td><\/tr><tr><td>Locked files<\/td><td>List of locked files and directories<\/td><td><code>\/-\/path_locks<\/code><\/td><td>Premium and Ultimate only<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Lab setup before you start<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a blank project with <strong>Initialize repository with a README<\/strong> selected, so <code>main<\/code> has at least one commit. Without a commit you can&#039;t create branches or tags from the UI.<\/li>\n\n\n<li>Make sure you have at least the <strong>Developer<\/strong> role. You need <strong>Maintainer<\/strong> to change protected branch or protected tag settings.<\/li>\n\n\n<li>Add a few files to work with, for example <code>app.sh<\/code>, <code>config.yaml<\/code> and an image or <code>.psd<\/code> file for the file-locking exercise.<\/li>\n\n\n<li>If you plan to use the CLI, set up an SSH key or a personal access token with <code>read_repository<\/code> and <code>write_repository<\/code> scopes for HTTPS cloning.<\/li>\n\n\n<li>Invite a second user (or a classmate) as Developer so you can practise assigning reviewers and approving merge requests.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> The <code>main<\/code> 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&#039;s why the lab uses a feature branch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The same lab from the command line<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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&#039;s URL.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"># Clone and create the feature branch\ngit clone git@gitlab.com:<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">namespace<\/span>&gt;<\/span>\/<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">project<\/span>&gt;<\/span>.git\ncd <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">project<\/span>&gt;<\/span>\ngit switch -c feature-xyz\n\n# Make and commit a change\necho 'echo \"hello from feature-xyz\"' &gt;&gt; app.sh\ngit add app.sh\ngit commit -m \"Add greeting to app.sh\"\n\n# Push the branch and open a merge request in one step\ngit push -u origin feature-xyz \\\n  -o merge_request.create \\\n  -o merge_request.target=main \\\n  -o merge_request.title=\"Add greeting to app.sh\"\n\n# Inspect history locally (similar to Commits and Repository graph)\ngit log --oneline --graph --all\n\n# Compare branches (similar to Compare revisions)\ngit fetch origin\ngit diff origin\/main...origin\/feature-xyz --stat\n\n# After the MR is merged, tag the release on main\ngit switch main\ngit pull\ngit tag -a v1.0.0 -m \"First release\"\ngit push origin v1.0.0<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The <code>-o merge_request.*<\/code> push options tell GitLab to create the merge request while the push is processed, and the response includes a link to it. <code>git tag -a<\/code> creates an annotated tag, which stores the tagger and a message. GitLab release pages and most versioning tools work best with annotated tags.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Corrections and clarifications to the lab steps<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Commits, step 4:<\/strong> the Commits page has no <code>Compare<\/code> tab. To compare two commits, use <strong>Code \u2192 Compare revisions<\/strong> and paste the two commit SHAs into the source and target fields.<\/li>\n\n\n<li><strong>Tags, step 3:<\/strong> in the <strong>New tag<\/strong> form, set <strong>Create from<\/strong> to <code>main<\/code> or to a specific commit SHA. If you fill in <strong>Message<\/strong>, GitLab creates an annotated tag. If you leave it empty, you get a lightweight tag.<\/li>\n\n\n<li><strong>Merge requests, step 2:<\/strong> pick <code>feature-xyz<\/code> as the <strong>source branch<\/strong> and <code>main<\/code> as the <strong>target branch<\/strong>, then select <strong>Compare branches and continue<\/strong>. If the branch was pushed recently, the banner on the project page offers a quicker <strong>Create merge request<\/strong> button.<\/li>\n\n\n<li><strong>Merge requests, step 6:<\/strong> on the Free tier anyone eligible can approve, but approvals are not required before merging. Required approval rules need Premium or Ultimate.<\/li>\n\n\n<li><strong>Snippets, step 4:<\/strong> a project snippet can&#039;t be more visible than its project. On GitLab.com, <strong>Internal<\/strong> visibility is not available for new snippets, so choose Private or Public.<\/li>\n\n\n<li><strong>Locked files:<\/strong> 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.<\/li>\n\n\n<li><strong>Repository:<\/strong> the main file browser is <strong>Code \u2192 Repository<\/strong>. Single-file edits use <strong>Edit \u2192 Edit single file<\/strong>, and multi-file edits use <strong>Edit \u2192 Web IDE<\/strong>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How file locking actually works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">GitLab offers two kinds of lock, and they behave differently:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Lock type<\/th><th>How to create it<\/th><th>Scope<\/th><th>Tier<\/th><\/tr><\/thead><tbody><tr><td>Default branch file and directory lock<\/td><td>Open the file or folder in the Repository view and select <strong>Lock<\/strong><\/td><td>Blocks other users from pushing or merging changes to that path on the default branch<\/td><td>Premium and Ultimate<\/td><\/tr><tr><td>Exclusive file lock (Git LFS)<\/td><td><code>git lfs lock &lt;file&gt;<\/code> on a file tracked as lockable<\/td><td>Blocks other users from pushing changes to that file on any branch<\/td><td>All tiers, requires Git LFS<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For binary files such as <code>logo.psd<\/code>, Git LFS locking is the better fit because it works on every branch and from the command line:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">git lfs install\ngit lfs track <span class=\"hljs-string\">\"*.psd\"<\/span> --lockable\ngit add .gitattributes logo.psd\ngit commit -m <span class=\"hljs-string\">\"Track PSD files with LFS as lockable\"<\/span>\ngit push\n\ngit lfs lock logo.psd      <span class=\"hljs-comment\"># take the lock<\/span>\ngit lfs locks              <span class=\"hljs-comment\"># list current locks<\/span>\ngit lfs unlock logo.psd    <span class=\"hljs-comment\"># release it when done<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\"><strong>Note:<\/strong> Files marked <code>--lockable<\/code> are checked out as read-only until you lock them. This reminds everyone to take the lock before editing. Maintainers can remove another user&#039;s lock with <code>git lfs unlock --force<\/code> or from the Locked files page.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Useful quick actions in merge requests<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Quick action<\/th><th>Effect<\/th><\/tr><\/thead><tbody><tr><td><code>\/assign @user<\/code><\/td><td>Assigns the merge request<\/td><\/tr><tr><td><code>\/assign_reviewer @user<\/code><\/td><td>Requests a review from a user<\/td><\/tr><tr><td><code>\/label ~bug ~frontend<\/code><\/td><td>Adds labels (they must already exist)<\/td><\/tr><tr><td><code>\/estimate 2h<\/code><\/td><td>Sets a time estimate<\/td><\/tr><tr><td><code>\/spend 30m<\/code><\/td><td>Logs time spent<\/td><\/tr><tr><td><code>\/draft<\/code><\/td><td>Marks the merge request as draft so it can&#039;t be merged yet<\/td><\/tr><tr><td><code>\/approve<\/code><\/td><td>Approves the merge request<\/td><\/tr><tr><td><code>\/merge<\/code><\/td><td>Merges, or sets auto-merge if a pipeline is running<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Common errors and fixes<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td><code>You are not allowed to push code to protected branches on this project<\/code><\/td><td>Pushing directly to protected <code>main<\/code><\/td><td>Push to a feature branch and open a merge request, or ask a Maintainer to adjust <strong>Settings \u2192 Repository \u2192 Protected branches<\/strong><\/td><\/tr><tr><td>Merge button disabled<\/td><td>Merge conflicts, unresolved threads, a failed or required pipeline, or missing approvals<\/td><td>Read the merge checks panel on the merge request, then resolve conflicts or threads, or rerun the pipeline<\/td><\/tr><tr><td>Cannot create branch or tag in the UI<\/td><td>Repository is empty<\/td><td>Commit a README first<\/td><\/tr><tr><td>Tag creation fails<\/td><td>Tag name already exists or the tag pattern is protected<\/td><td>Use a new version number, or get a role allowed to create protected tags<\/td><\/tr><tr><td><strong>Locked files<\/strong> missing from the menu<\/td><td>Instance or namespace is on the Free tier<\/td><td>Use Git LFS exclusive locks<\/td><\/tr><tr><td>Push rejected for a specific file<\/td><td>Another user holds a lock on that path<\/td><td>Run <code>git lfs locks<\/code> or check the Locked files page, then ask the owner to unlock<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Good habits to take from this lab<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep branches short-lived and name them after the work, such as <code>feature\/login-form<\/code> or <code>fix\/123-null-check<\/code>.<\/li>\n\n\n<li>Write commit messages in the imperative mood (&quot;Add greeting&quot;) and reference issues with <code>#123<\/code> so GitLab links them.<\/li>\n\n\n<li>Use semantic version tags (<code>v1.0.0<\/code>) and protect the <code>v*<\/code> pattern so only Maintainers can create release tags.<\/li>\n\n\n<li>Turn on <strong>Delete source branch<\/strong> when merging so stale branches don&#039;t pile up.<\/li>\n\n\n<li>Never store secrets in snippets, even private ones. Use CI\/CD variables instead. To continue into pipelines, see <a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-gitlab-ci-cd-and-use-cases-of-gitlab-ci-cd\/\">What is GitLab CI\/CD and use cases of GitLab CI\/CD?<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Where is the Repository graph in the new GitLab navigation?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open the project and go to <strong>Code \u2192 Repository graph<\/strong> in the left sidebar. You can also add <code>\/-\/network\/&lt;branch&gt;<\/code> to the project URL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why can&#039;t I see Locked files in my GitLab project?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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 <code>git lfs lock<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between a lightweight and an annotated tag in GitLab?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I create a merge request without opening the GitLab UI?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Push with <code>git push -o merge_request.create -o merge_request.target=main<\/code>, and GitLab creates the merge request and returns its link in the push output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why can&#039;t I push to main in my GitLab project?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Related tutorials<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/gitlab-lab-plan-step-by-step-tutorial-gitlab-cloud\/\">Gitlab Lab \u2013 Plan \u2013 Step-by-Step Tutorial: GitLab Cloud<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/what-is-gitlab-ci-cd-and-use-cases-of-gitlab-ci-cd\/\">What is GitLab CI\/CD and use cases of GitLab CI\/CD?<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/gitlab-hierarchy-organization-namespace-group-project\/\">GitLab Hierarchy: Organization, Namespace, Group &amp; Project<\/a><\/li>\n\n\n<li><a href=\"https:\/\/www.devopsschool.com\/blog\/category\/devops\/gitlab\/\">More GitLab tutorials<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5112],"tags":[],"class_list":["post-49490","post","type-post","status-publish","format-standard","hentry","category-gitlab"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=49490"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49490\/revisions"}],"predecessor-version":[{"id":80177,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/49490\/revisions\/80177"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=49490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=49490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=49490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}