Day 3: Working with GitLab Repositories

Search for a command to run...

No comments yet. Be the first to comment.
Master GitLab from scratch with this complete step-by-step DevOps series. Learn GitLab fundamentals, repositories, branching, merge requests, CI/CD pipelines, GitLab Runner, Docker, Kubernetes integration, security, deployments, and real-world DevOps workflows. Whether you're a beginner or preparing for DevOps interviews, this series will help you gain practical GitLab skills through hands-on examples and projects.
Learn Continuous Integration, Continuous Delivery, Pipelines, Stages, Jobs & .gitlab-ci.yml π Introduction In the previous articles, we explored GitLab fundamentals, repository management, and collab
Master GitLab CI/CD Variables, Secrets Management, Artifacts & Best Practices π Introduction In the previous article, we learned how GitLab Runners execute CI/CD pipelines and how to configure Self-H

Learn GitLab Runners, Hosted vs Self-Hosted Runners, Runner Registration, Tags, Pipeline Editor & Parallel Jobs π Introduction In the previous article, we created our first GitLab CI/CD pipeline and

Learn Continuous Integration, Continuous Delivery, Pipelines, Stages, Jobs & .gitlab-ci.yml π Introduction In the previous articles, we explored GitLab fundamentals, repository management, and collab

Learn Docker Scout, Multi-Stage Builds, Docker Hardened Images (DHI), SBOM, Docker Model Runner, Ask Gordon AI, and production-ready container security through practical, real-world examples. Introduc

Import Repositories, Mirroring & Repository Management Best Practices
In the previous articles, we learned the fundamentals of GitLab, created projects, and configured secure authentication using SSH Keys and Personal Access Tokens.
Now it's time to start working with GitLab repositories.
In this guide, you'll learn how to migrate existing repositories from GitHub, keep repositories synchronized using mirroring, understand the difference between Merge Requests and Pull Requests, and follow repository management best practices used by professional DevOps teams.
By the end of this article, you'll know how to manage GitLab repositories efficiently in both personal and enterprise environments.
After completing this article, you'll understand:
β Import a GitHub repository into GitLab
β Repository Mirroring
β Push Mirroring vs Pull Mirroring
β Merge Request vs Pull Request
β Repository Management Best Practices
Before continuing, make sure you have:
A GitLab account
A GitHub account
Basic knowledge of Git
An existing Git repository (optional)
Many developers and organizations already host their source code on GitHub. If you decide to use GitLab for its powerful CI/CD, security features, or DevOps platform, you don't need to recreate your repositories from scratch.
GitLab provides a built-in Import Project feature that allows you to migrate an existing GitHub repositoryβincluding its commit historyβto GitLab in just a few steps.
This makes migration simple while preserving your existing development history.
Importing a repository saves time and ensures that your existing project history remains intact.
Common reasons to import a repository include:
Migrating from GitHub to GitLab
Using GitLab CI/CD with an existing project
Consolidating repositories into one platform
Moving company projects to GitLab
Follow these steps to import your repository into GitLab.
Log in to your GitLab account and click Project.
Select Import Project, then choose GitHub as the import source.
GitLab will ask you to authorize access to your GitHub account.
Grant the required permissions so GitLab can read your repositories.
Choose the repository you want to import and click Import.
GitLab will automatically copy the repository, including its commit history.
Once the import is complete, open the repository in GitLab and verify that:
Source code is available
Commit history is preserved
Branches are imported successfully
Your project is now ready to use in GitLab.
Repository Mirroring is a feature that automatically synchronizes repositories between GitLab and another Git hosting platform, such as GitHub, Bitbucket, or another GitLab instance.
Instead of manually pushing or pulling changes, GitLab keeps the repositories synchronized based on the configured mirroring direction.
Repository mirroring is especially useful for organizations managing projects across multiple Git platforms or maintaining backup repositories.
Repository mirroring helps keep code synchronized across different platforms without requiring manual intervention.
Common use cases include:
Migrating from GitHub to GitLab gradually
Maintaining a backup repository
Synchronizing code across multiple Git platforms
Supporting teams working on different Git hosting services
GitLab supports two types of repository mirroring:
Pull Mirroring
Push Mirroring
The difference lies in the direction in which changes are synchronized.
In Pull Mirroring, GitLab periodically pulls changes from another remote repository and updates the local GitLab repository automatically.
Whenever new commits are pushed to the source repository, GitLab fetches those changes during the next synchronization.
GitHub Repository
β
β Pull Changes
βΌ
GitLab Repository
Migrating repositories from GitHub
Keeping GitLab updated from another platform
Read-only synchronization
In Push Mirroring, GitLab automatically pushes changes from its repository to another remote repository whenever new commits are added.
This ensures that both repositories remain synchronized.
GitLab Repository
β
β Push Changes
βΌ
GitHub Repository
Maintaining backup repositories
Publishing code to multiple Git platforms
Disaster recovery strategies
| Feature | Pull Mirroring | Push Mirroring |
|---|---|---|
| Direction | External Repository β GitLab | GitLab β External Repository |
| Updates Triggered By | External repository changes | GitLab repository changes |
| Primary Purpose | Import and synchronize code | Backup and distribution |
| Common Use Case | GitHub to GitLab migration | GitLab to GitHub backup |
If you've worked with GitHub before, you've probably heard the term Pull Request (PR). In GitLab, the same concept is called a Merge Request (MR).
Both are used to propose code changes, review them, discuss improvements, and merge them into the main branch. The primary difference is the terminology used by each platform.
A Merge Request (MR) is a GitLab feature that allows developers to propose changes from one branch to another before merging.
Instead of directly pushing code to the main branch, developers create a Merge Request so teammates can review the changes, suggest improvements, run CI/CD pipelines, and approve the code.
This review process helps maintain code quality and reduces the chances of introducing bugs into production.
A Pull Request (PR) is GitHub's implementation of the same workflow.
After completing work on a feature branch, developers open a Pull Request to request that their changes be merged into another branch, usually the main or develop branch.
Like Merge Requests, Pull Requests support code reviews, comments, approvals, and automated CI/CD checks.
Imagine you're developing a new login feature.
Instead of committing your changes directly to the main branch, you create a separate feature branch.
After completing the feature, you open a Merge Request (or Pull Request in GitHub).
Your teammates review the code, provide feedback, and approve the changes. Once all checks pass, the feature is merged into the main branch.
A well-managed repository is easier to maintain, collaborate on, and scale as your project grows. Following repository management best practices helps improve code quality, reduces conflicts, and makes collaboration more efficient.
Whether you're working on a personal project or contributing to an enterprise application, adopting these practices from the beginning will save time and effort in the long run.
Organize your project with a consistent folder structure so developers can easily navigate the codebase.
A README.md file is often the first thing contributors see. It should explain:
Project overview
Installation steps
Usage instructions
Prerequisites
Contribution guidelines
A well-written README helps new developers get started quickly.
Avoid generic branch names like:
test
new
abc
Instead, use descriptive names such as:
feature/user-authentication
bugfix/login-error
hotfix/payment-api
Meaningful branch names make collaboration easier and improve project organization.
Protect critical branches like main and develop to prevent accidental changes.
Instead of pushing directly, require developers to submit Merge Requests for review and approval.
This helps maintain code quality and reduces the risk of introducing bugs.
Write commit messages that describe what changed.
β Good Examples:
Add user authentication API
Fix Docker build issue
Update Kubernetes deployment configuration
β Avoid:
update
fix
changes
Clear commit messages make it easier to understand project history.
Always review code through a Merge Request before merging it into the main branch.
Code reviews help:
Identify bugs early
Improve code quality
Share knowledge across the team
Maintain coding standards
As the project evolves, update your documentation regularly.
Important files include:
Project Wiki
Up-to-date documentation makes onboarding and maintenance much easier.
Congratulations! π You have successfully completed Day 3 of the GitLab learning series.
In this article, you learned how to import existing GitHub repositories into GitLab, synchronize repositories using Repository Mirroring, understand the difference between Merge Requests and Pull Requests, and follow repository management best practices used by professional development teams.
These concepts form the foundation of an efficient Git workflow and prepare you for collaborating on real-world software projects using GitLab.
Hi, I'm Apurv Gujjar, a DevOps Engineer passionate about Cloud, AWS, Kubernetes, Docker, Terraform, GitLab, and Infrastructure Automation.
I share practical DevOps tutorials, real-world projects, certification guides, interview preparation, and cloud engineering best practices to help students and professionals build production-ready skills.
π§ Email: gujjarapurv181@gmail.com
π Portfolio: https://www.apurv-gujjar.co.in
π GitHub: https://github.com/ApurvGujjar07
πΌ LinkedIn: https://www.linkedin.com/in/apurv-gujjar
If you enjoy DevOps, Cloud, and GitLab content, feel free to connect with me. I'm always happy to share knowledge and discuss modern cloud technologies.