Welcome to the GitLab Lab Manual for the Code section. This hands-on guide will walk you through using essential version control and collaboration tools available under a GitLab project’s Code tab.
By the end of this lab, you will be able to:
- Navigate and manage a Git repository using GitLab UI
- Work with branches, commits, and tags
- Use merge requests to review and merge changes
- Visualize repository history and differences
- Use GitLab snippets and lock files for special file handling
- A GitLab account (GitLab.com or self-managed instance)
- A sample GitLab project (or fork an existing public one)
- Git installed (for optional local work)
Explore the main repository view
- Go to your project → Code → Repository
- Browse the file structure
- Click files to view content
- Try editing a file via the Web IDE
Create and switch between branches
- Navigate to
Code → Branches
- Click
New branch
- Name it
feature-xyz
- You can now switch to this branch from the dropdown on the file view
- Make changes to files in this branch
Track project history
- Go to
Code → Commits
- View a list of all commits
- Click any commit hash to view its details
- Use the
Compare
tab to see changes between commits
Mark release points
- Go to
Code → Tags
- Click
New Tag
- Tag your latest commit as
v1.0.0
- Use tags in CI/CD and release pages
Merge changes from feature branch to main
- Go to
Code → Merge Requests → New Merge Request
- Select
feature-xyz
intomain
- Add a title, description
- Assign to reviewer
- Submit and discuss changes in comments
- Approve and merge once complete
Visualize branch and merge activity
- Navigate to
Code → Repository Graph
- This will show branching and merge paths
- Useful to understand team workflows and commit timelines
Compare branches or tags
- Go to
Code → Compare Revisions
- Choose
main
vsfeature-xyz
- View all file diffs and commit list
Share reusable code snippets
- Go to
Code → Snippets
- Click
New Snippet
- Paste your code (e.g., sample shell script)
- Set visibility (private/internal/public)
- Save and share the link
Prevent edits to non-mergeable files
- Navigate to
Code → Locked Files
- Click “Lock a file”
- Choose a binary/design file (e.g.,
logo.psd
) - Only you can now edit this file until unlocked
- Use
/label
,/assign
, and/estimate
in merge request comments - Clone project locally and push commits using Git
- Use
.gitlab-ci.yml
to add CI pipelines
You've now explored all the tools under GitLab's Code tab. These features are essential for working collaboratively, tracking project evolution, and managing source code efficiently.
Happy coding! 🚀