Day 3: Working with GitLab Repositories

Import Repositories, Mirroring & Repository Management Best Practices
π Introduction
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.
π― What You'll Learn
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
π Prerequisites
Before continuing, make sure you have:
A GitLab account
A GitHub account
Basic knowledge of Git
An existing Git repository (optional)
π₯ Importing a GitHub Repository into GitLab
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.
π Why Import a Repository?
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
π Steps to Import a GitHub Repository
Follow these steps to import your repository into GitLab.
Step 1: Sign in to GitLab
Log in to your GitLab account and click Project.
Step 2: Choose Import Project
Select Import Project, then choose GitHub as the import source.
Step 3: Authorize GitHub
GitLab will ask you to authorize access to your GitHub account.
Grant the required permissions so GitLab can read your repositories.
Step 4: Select the Repository
Choose the repository you want to import and click Import.
GitLab will automatically copy the repository, including its commit history.
Step 5: Verify the Import
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
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.
π€ Why Use Repository Mirroring?
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
π Types of Repository Mirroring
GitLab supports two types of repository mirroring:
Pull Mirroring
Push Mirroring
The difference lies in the direction in which changes are synchronized.
β¬οΈ Pull Mirroring
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.
Example
GitHub Repository
β
β Pull Changes
βΌ
GitLab Repository
Best Use Cases
Migrating repositories from GitHub
Keeping GitLab updated from another platform
Read-only synchronization
β¬οΈ Push Mirroring
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.
Example
GitLab Repository
β
β Push Changes
βΌ
GitHub Repository
Best Use Cases
Maintaining backup repositories
Publishing code to multiple Git platforms
Disaster recovery strategies
βοΈ Pull Mirroring vs Push Mirroring
| 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 |
π Merge Request vs Pull Request
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.
π€ What is a Merge Request?
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.
π€ What is a Pull Request?
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.
πΌ Real-World Example
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.
This workflow helps teams collaborate safely while maintaining high code quality.
π Repository Management Best Practices
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.
β 1. Use a Clear Repository Structure
Organize your project with a consistent folder structure so developers can easily navigate the codebase.
β 2. Write a Good README
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.
β 3. Use Meaningful Branch Names
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.
β 4. Protect Important Branches
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.
β 5. Keep Commit Messages Clear
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.
β 6. Review Code Before Merging
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
β 7. Keep Documentation Updated
As the project evolves, update your documentation regularly.
Important files include:
Project Wiki
Up-to-date documentation makes onboarding and maintenance much easier.
π― Summary
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.
π¨βπ» About the Author
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.
π¬ Connect With Me
π§ 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.





