USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

Introduction to GitHub and GitLab

Lesson 8/24 | Study Time: 60 Min

GitHub and GitLab are two of the most widely used platforms in the world for hosting Git repositories and enabling team collaboration.

While Git itself is a command-line tool that runs on your local machine, GitHub and GitLab provide a rich, web-based environment built on top of Git, adding powerful features like pull requests, code reviews, issue tracking, CI/CD pipelines, and much more.

Think of Git as the engine and GitHub or GitLab as the vehicle that makes that engine accessible, visual, and collaborative for entire teams and organizations.

What is GitHub?

GitHub is a cloud-based platform for hosting Git repositories, launched in 2008 and acquired by Microsoft in 2018. It is the largest code hosting platform in the world, with over 100 million developers and millions of repositories, both public and private.

GitHub is built around Git but extends it significantly with a web interface and collaboration tools that make working in teams far more structured and efficient.


What GitHub Offers


1. Repository Hosting: Store and manage Git repositories in the cloud, accessible from anywhere.

2. Pull Requests (PRs): A structured way to propose, review, discuss, and merge code changes.

3. Code Review: Teammates can comment on specific lines of code, suggest changes, and approve or reject contributions.

4. Issues and Project Boards: Track bugs, feature requests, and tasks directly within the repository.

5. GitHub Actions: A built-in CI/CD automation platform that triggers workflows on code events.

6. GitHub Pages: Host static websites directly from a repository.Security Features — Automated vulnerability scanning, Dependabot alerts, and secret scanning

7. Open Source Community: The go-to platform for open-source projects, where anyone can contribute to public repositories.


GitHub is where the world's software is built, from individual side projects to the world's most critical open-source infrastructure.

What is GitLab?

GitLab is an open-source, web-based DevOps platform that provides Git repository hosting alongside a comprehensive suite of tools covering the entire software development lifecycle — from planning and coding to testing, deployment, and monitoring.


GitLab was founded in 2011 and is available in two forms:


1. GitLab.com: A cloud-hosted version, similar to GitHub.

2. Self-hosted GitLab: Organizations can install and run GitLab on their own servers, giving them full control over their data and infrastructure.


What GitLab Offers


1. Repository Hosting: Full Git repository management with a clean web interface.

2. Merge Requests (MRs): GitLab's equivalent of GitHub's Pull Requests, used for code review and merging.

3. Built-in CI/CD Pipelines: GitLab CI/CD is deeply integrated and considered one of the most powerful built-in pipeline systems available.

4. Issue Tracking and Boards: Plan and manage work with issues, milestones, and Kanban-style boards.

5. Container Registry: Store and manage Docker images directly within GitLab.

6. Security and Compliance: Built-in SAST, DAST, dependency scanning, and license compliance tools.

7. GitLab Pages: Host static websites from repositories.

8. Self-Hosting Option: Run the entire platform on your own infrastructure.

Core Features of Both Git Hub and Git Lab

Both GitHub and GitLab share a set of core features that every developer interacts with regularly. Understanding these features is essential for working effectively on either platform.

Repositories

A repository on GitHub or GitLab is the home of your project. It contains all your code, commit history, branches, and associated resources. Repositories can be:


Public — Visible to anyone on the internet; commonly used for open-source projects.

Private — Visible only to authorized team members; used for proprietary or sensitive projects.


When you create a repository on GitHub or GitLab, you can initialize it with:


1. A README file: A description of the project displayed on the repository's homepage

2. A .gitignore file: Specifies files Git should not track (e.g., log files, environment variables).

3. A license: Defines the terms under which others can use your code.

Pull Requests and Merge Requests

This is arguably the most important collaboration feature on both platforms. A Pull Request (GitHub) or Merge Request (GitLab) is a formal proposal to merge code from one branch into another.


A typical PR/MR workflow looks like this:


1. Developer pushes a feature branch to the remote repository.

2. Developer opens a Pull Request / Merge Request describing the changes.

3. Teammates review the code, leave comments, and suggest improvements.

4. Automated CI/CD checks run and must pass before merging is allowed.

5. One or more approvals are obtained from reviewers.

6. The branch is merged into main and the PR/MR is closed.


This process ensures that no code reaches the main branch without being reviewed, tested, and approved, a critical quality gate in professional DevOps workflows.

Issues

Issues are used to track bugs, feature requests, questions, and tasks within a repository. Every issue can have:


1. A title and detailed description

2. Labels (e.g., bug, enhancement, documentation)

3. An assignee — the person responsible for addressing it

4. A milestone — the version or sprint it belongs to

5. Comments and discussions between team members


Issues connect directly to code — developers can reference an issue in a commit message or pull request, automatically linking code changes to the work item they address.

CI/CD Integration

GitHub Actions uses workflow files written in YAML, stored in the .github/workflows/ directory of your repository.

A workflow is triggered by events, such as a push to main or the opening of a pull request — and runs automated jobs like building, testing, and deploying code.

GitLab CI/CD uses a single configuration file called .gitlab-ci.yml stored at the root of the repository. It defines stages and jobs that run automatically in response to code events, with powerful features like parallel jobs, environments, and deployment approvals.

Both systems connect your code repository directly to your delivery pipeline, the moment code is pushed, the pipeline begins automatically.

Wikis and Documentation

Both platforms include a built-in Wiki feature where teams can write and maintain project documentation. This keeps documentation close to the code in the same platform where development happens, making it easier to keep up to date.

Getting Started with GitHub

Getting started with GitHub is straightforward. Here is a step-by-step overview:

Step 1 — Create an account

Visit github.com and sign up for a free account. A free account gives you access to unlimited public and private repositories.

Step 2 — Create a new repository

Click the "+" icon and select "New repository." Give it a name, choose public or private, and optionally initialize it with a README.

Step 3 — Clone the repository to your local machine


Step 4 — Make changes, commit, and push


Step 5 — Open a Pull Request

Push a feature branch to GitHub and click "Compare & pull request" in the GitHub interface to open a PR for review.

Getting Started with GitLab

Step 1 — Create an account

Visit gitlab.com and sign up for a free account. GitLab's free tier is generous and includes CI/CD pipeline minutes.

Step 2 — Create a new project

In GitLab, repositories are called projects. Click "New project," give it a name, and choose its visibility level.

Step 3 — Clone the project


Step 4 — Make changes, commit, and push

Step 5 — Open a Merge Request

Push a feature branch to GitLab and navigate to the repository to open a Merge Request for review and approval.

Authentication — Connecting Git to GitHub or GitLab

When pushing or pulling from GitHub or GitLab, Git needs to verify your identity. There are two primary authentication methods:


1. HTTPS with Personal Access Token (PAT)

Modern GitHub and GitLab no longer accept plain passwords for HTTPS authentication. Instead, you generate a Personal Access Token from your account settings and use it as your password when prompted.

2. SSH Keys

SSH key authentication is more secure and eliminates the need to enter credentials repeatedly. To set it up:

Generate an SSH key pair on your local machine:


Copy the public key:

Paste the public key into your GitHub or GitLab account under Settings → SSH Keys.

Test the connection to GitHub:


Test the connection to GitLab:


Best Practices for Using GitHub and GitLab


1. Always write a clear Pull / Merge Request description: Explain what the change does, why it was made, and any relevant context

2. Link PRs/MRs to issues: Use keywords like "Closes #42" in your PR description to automatically close the related issue when merged

3. Use labels and milestones: Keep issues and PRs organized so the team always knows the status and priority of work

4. Protect the main branch: Enable branch protection rules so that direct pushes to main are blocked and all merges require a review

5. Review code thoroughly: When reviewing a teammate's PR, be constructive, specific, and kind

6. Keep repositories clean: Delete merged branches regularly to avoid clutter

7. Write a good README: Every repository should have a README that clearly explains what the project is, how to set it up, and how to contribute