Skip to content
Tutorials Center
My learning

Topics

Lesson 60 of 78 ยท GitHub and Platforms

GitLab, Bitbucket and Self-Hosting

Compare GitHub, GitLab, Bitbucket and Gitea, see how merge requests differ from pull requests, mirror and migrate repositories with plain Git, and learn self-hosting basics.

Git is the tool; GitHub, GitLab, Bitbucket and Gitea are hosting platforms built around it. They all give you the same core thing: a central place where repositories live, where people can push and pull, and where teams review code. On top of that, each adds its own extras: issue trackers, review screens, CI pipelines, wikis, package registries and permissions.

Because the platforms share Git underneath, moving between them is much easier than most people fear. This lesson compares the main options, explains the vocabulary differences (pull request or merge request?), shows how to mirror and migrate a repository using nothing but Git, and covers the basics of running your own server. The sandbox has no network and none of these services, so we use local bare repositories as stand-ins for the remote servers. That is exactly what a hosted repository is: a bare repository with a web interface on top.

The main platforms

Platform Typical use Notes
GitHub Open source, most companies Largest community; Actions for CI; owned by Microsoft
GitLab Companies wanting one tool for everything Built-in CI/CD, issue boards, container registry; can be self-hosted (Community or Enterprise edition)
Bitbucket Teams already using Jira Tight Jira and Trello integration; owned by Atlassian
Gitea / Forgejo Small teams, home labs, self-hosting Lightweight, one binary, easy to run on a small server
Azure DevOps Microsoft-centric companies Repos, boards, pipelines in one suite
Codeberg, SourceHut Open-source projects that prefer non-profit or minimal hosting Codeberg runs Forgejo; SourceHut is email-patch oriented

None of these is "the real Git". They all speak the same protocols (see Transfer Protocols), so git clone, git fetch and git push work the same way against every one of them. What differs is everything around the repository.

Features, prices and names change often (Forgejo, for example, started as a fork of Gitea). Treat the table as a map of ideas, not a buying guide, and check each project's current documentation before you decide.

Pull request or merge request?

The same idea has different names:

Concept GitHub / Bitbucket / Gitea GitLab
Propose a change for review Pull request (PR) Merge request (MR)
Copy of a repository under your account Fork Fork
Pipeline definition file .github/workflows/*.yml .gitlab-ci.yml
Short-lived CI machine runner (hosted or self-hosted) runner
Issue templates .github/ISSUE_TEMPLATE/ .gitlab/issue_templates/
Code owners file CODEOWNERS CODEOWNERS

The words differ because of how each platform sees the action. A pull request says "please pull my changes". A merge request says "please merge my branch". Underneath, both are a request to take a branch (from the same repository or from a fork) and combine it into a target branch after review. The review workflow is described in Pull Requests and Code Review.

Special reference namespaces

Here is a detail that explains a lot. When you open a pull request, the platform stores the proposed commits under a special ref inside the server's repository: GitHub uses refs/pull/<number>/head, and GitLab uses refs/merge-requests/<number>/head. These are not branches, so they do not show up in git branch -r, but you can fetch them with an explicit refspec to check out someone's proposal locally.

We can simulate this with a local bare repository. Notice that we create the special ref ourselves, because there is no web interface to do it for us.

Bash Fetch a pull request ref from a server-like repository

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

After the clone, the reviewer sees only origin/HEAD and origin/main. The refs/pull/7/head ref is invisible to normal branch listings, but the explicit refspec refs/pull/7/head:pr-7 copies it into a local branch called pr-7. Many people add this to their configuration so every pull request is fetched automatically:

INI
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

(Read-only; for GitLab replace pull with merge-requests.) With that second fetch line, git fetch brings in origin/pr/7, origin/pr/8 and so on. The + allows the ref to move when the author force-pushes.

GitLab at a glance

GitLab's main selling point is that it bundles the whole life cycle: repositories, issues, merge requests, CI/CD pipelines, a package and container registry, and security scanning, all in one product and one permission model. A project's pipeline is described by a .gitlab-ci.yml file in the repository root. The idea is the same as GitHub Actions (see GitHub Actions) but the file looks different:

YAML
# .gitlab-ci.yml (read-only: needs a GitLab runner)
stages:
  - test
  - build

unit-tests:
  stage: test
  image: node:24
  script:
    - npm ci
    - npm test

package:
  stage: build
  image: node:24
  script:
    - npm run build
  artifacts:
    paths:
      - dist/
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

Vocabulary: a pipeline is one run; it consists of stages that run in order; each stage contains jobs that run in parallel; each job runs its script lines in a fresh container started from image. Artifacts are files a job passes on or keeps. Rules decide when a job runs. Predefined variables such as $CI_COMMIT_BRANCH describe the current run.

Since YAML mistakes are common, teams often add a check before pushing. The stand-in below verifies the three things every GitLab job needs: a stage that is declared, a script and a unique name.

Bash A tiny .gitlab-ci.yml sanity check (fails on purpose)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Run it: it prints stage 'deploy' is not declared and job 'lint' has no script and exits with status 1. Those are the two real problems: package uses a stage called deploy that is not in the stages list, and lint has no script. GitLab would refuse the pipeline for either. A real project would use GitLab's built-in CI linter, but a few lines of shell show how shallow most of these mistakes are.

Bitbucket, Gitea and friends

Bitbucket (Cloud and Data Center) follows the GitHub vocabulary: pull requests, forks, branch permissions. Its CI is Bitbucket Pipelines, configured in bitbucket-pipelines.yml. Its strength is the integration with Jira: a branch named PROJ-123-fix-login or a commit message mentioning PROJ-123 links to that Jira issue automatically.

Gitea and its fork Forgejo are small, fast, self-hostable platforms that mimic GitHub's interface: repositories, issues, pull requests, a wiki, packages and an Actions-compatible CI. A single Go binary and a small SQLite or PostgreSQL database are enough for a team.

Azure DevOps bundles Git repositories with boards and pipelines in the Microsoft ecosystem.

When you evaluate a platform, ask these questions:

  1. Where do we want the data? Hosted by a vendor, in a region, or on our own servers.
  2. What do we already use? Jira, Slack, an identity provider (SSO), a cloud provider.
  3. What do reviews and CI need? Required approvals, code owners, protected branches, large file storage, self-hosted runners.
  4. What does it cost at our size? Per-seat prices differ a lot.
  5. How easy is it to leave? Since the repository itself is portable, the answer depends on issues, wikis and CI files, which are not.

Mirroring a repository

A mirror is a copy that stays in sync with another repository, including all branches and tags. People mirror to have a backup, to publish a read-only copy on another platform, or to keep a self-hosted copy of a hosted project.

Git has two options for this. git clone --mirror makes a bare copy of everything (all refs, including remote-tracking and special refs), and git push --mirror pushes every ref to another repository, deleting remote refs that no longer exist locally.

Bash Mirror a repository to a second server

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Both servers list the same three refs (refs/heads/main, refs/heads/release, refs/tags/v1.0) with the same hashes (3adbc1a for main and the tag, 1c330d0 for release): since commit hashes depend only on content and history, the copy is identical. To keep the mirror up to date you would run git -C mirror.git remote update --prune and then the push again, from a scheduler such as cron or a CI job. GitLab and Gitea can also do this for you: they offer "pull mirrors" and "push mirrors" in the settings.

git push --mirror is destructive on the target: any branch or tag that does not exist in the source is deleted there. Only point it at a repository whose sole purpose is to be the mirror.

Migrating between platforms

A migration has two parts: the Git data and the platform data.

Git data (commits, branches, tags) is portable. The steps are exactly the mirror steps above: mirror-clone from the old host, create an empty repository on the new host, push with --mirror. After that, every developer changes the remote URL:

Bash Switch a clone to a new remote URL

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

git remote set-url only edits the configuration. History and the tracking branch origin/main stay the same, because the new server has identical commits. A second tool for large teams is the url.<base>.insteadOf setting, which rewrites URLs on the fly. For instance, git config --global url."[email protected]:".insteadOf "[email protected]:" makes old clones and old scripts talk to the new host without touching each repository (read-only; needs real hosts).

Platform data (issues, pull requests, wikis, labels, CI configuration) is not in the repository. Most platforms ship an importer (GitLab can import from GitHub, Gitea can migrate issues and pull requests from several sources), but expect gaps: comment authors, review state and attachments often survive only partly. For CI you will usually rewrite the pipeline file by hand. A realistic plan:

  1. Announce a freeze: no new pushes to the old host.
  2. Mirror the Git data and compare refs (as in the example above).
  3. Run the platform importer for issues and pull requests; spot-check a few.
  4. Port CI configuration and secrets (secrets are never exported; re-enter them).
  5. Update remote URLs, documentation badges and deployment hooks.
  6. Make the old repository read-only or archive it, with a link to the new location.

Self-hosting basics

You can host Git yourself at three levels of effort.

Level 1: a bare repository over SSH. Any machine with Git and SSH can be a server. Create a bare repository and give people access, and they use ssh:// or user@host:path URLs. There is no web interface, no pull requests and no CI, but for a private backup or a tiny team it works. Our examples above are this setup, using local paths instead of SSH.

Terminal
# on the server (read-only: needs a real machine)
git init --bare /srv/git/project.git

# on a laptop
git clone [email protected]:/srv/git/project.git

Level 2: a lightweight platform. Gitea or Forgejo give you a web interface, accounts, issues, pull requests and CI for the price of a small VPS. Typical production concerns: put it behind HTTPS (a reverse proxy such as Caddy or nginx), use a real database for more than a few users, and configure backups.

Level 3: a full platform. Self-managed GitLab covers everything but needs a bigger machine and regular upgrades.

Whatever you choose, remember what you now own:

  • Backups. A bare repository is just a folder, so git clone --mirror plus a database dump is a solid backup. Test your restore.
  • Security updates. An internet-facing Git server must be patched promptly.
  • Authentication. Use SSH keys or tokens; consider SSO for teams. See Signing, Credentials and Security.
  • Availability. If the server is down, nobody can push or review (though everyone still has a full local copy of the history, which is Git's quiet superpower).

Which one should you pick?

For learning and open source, GitHub is the default because contributors already have accounts. For a company that wants everything under one roof or on its own servers, GitLab is a strong choice. For a team on Jira, Bitbucket is convenient. For a small team that wants control and low cost, Gitea or Forgejo. And because the Git data is portable, the choice is not a trap: a mirror push is all it takes to leave.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the difference between a GitHub pull request and a GitLab merge request?

    Both are a reviewable proposal to bring a branch into another branch. The names differ; the workflow is the same.
  2. 2. Which command copies every ref of a repository, including tags, into a bare mirror?

    --mirror implies --bare and also maps all refs one to one. --bare alone only copies branches and tags in the usual layout.
  3. 3. What is a danger of git push --mirror?

    A mirror push makes the target refs match the source exactly, including deleting extra ones. Use it only on repositories meant to be mirrors.
  4. 4. Which data is NOT carried over by mirroring the Git repository to a new platform?

    Issues, wikis and review comments are stored by the platform, not in Git. Importers can help, but the data is not part of the repository.
  5. 5. After migrating, how does a developer point an existing clone at the new server?

    git remote set-url edits the remote's URL in the configuration. Because the new server has the same commits, nothing else changes.

Summary

  • GitHub, GitLab, Bitbucket, Gitea/Forgejo and others all host ordinary Git repositories; the extras (issues, review, CI) differ.
  • Pull request and merge request are two names for the same reviewable proposal; the platform keeps them under refs such as refs/pull/N/head.
  • .gitlab-ci.yml defines stages and jobs; it is the GitLab counterpart to GitHub Actions workflows.
  • git clone --mirror plus git push --mirror copies every branch and tag; commit hashes stay identical.
  • Issues, wikis and CI settings are platform data and need importers or manual work when you migrate.
  • git remote set-url (or url.<base>.insteadOf) redirects existing clones.
  • Self-hosting runs from a bare repository over SSH up to a full platform; you then own backups, updates and security.

Next: Contributing to Open Source