Skip to main content

Command Palette

Search for a command to run...

Day 3: Working with GitLab Repositories

Updated
β€’8 min readβ€’View as Markdown
Day 3: Working with GitLab Repositories
G
Gujjar Apurv is a passionate DevOps Engineer in the making, dedicated to automating infrastructure, streamlining software delivery, and building scalable cloud-native systems. With hands-on experience in tools like AWS, Docker, Kubernetes, Jenkins, Git, and Linux, he thrives at the intersection of development and operations. Driven by curiosity and continuous learning, Apurv shares insights, tutorials, and real-world solutions from his journeyβ€”making complex tech simple and accessible. Whether it's writing YAML, scripting in Python, or deploying on the cloud, he believes in doing it the right way. "Infrastructure is code, but reliability is art."

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:

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.

Complete GitLab DevOps Guide: From Beginner to Advanced

Part 3 of 6

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.

Up next

Day 4 GitLab CI/CD Pipelines

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