3.8. GitHub and GitLab
Table of Contents
Why Backend Developers Use GitHub and GitLab
As a backend developer, you will almost always store your code on a remote Git hosting platform. The two most popular options are GitHub and GitLab.
Both are built around Git, which you will already have learned as your version control system. Git works locally, on your machine. GitHub and GitLab act as:
- Remote backups of your repositories
- Collaboration platforms for teams
- Integration points for CI/CD, issue tracking, code review, and more
You can think of them as "social networks for code" plus many development tools.
In this chapter, you will see what is common between GitHub and GitLab, and where they differ, especially from a backend beginner's perspective.
Common Features: Git Hosting Platforms
GitHub and GitLab provide very similar core features. Understanding these shared features helps you switch between them easily.
Repositories
A repository (repo) on GitHub or GitLab is the remote copy of your local Git repository.
Typical workflow:
- You have a local repo created with
git initor cloned. - You create a remote repo on GitHub or GitLab (usually via the website).
- You connect local and remote:
git remote add origin git@github.com:username/project-name.git
# or
git remote add origin git@gitlab.com:username/project-name.git- You push your code:
git push -u origin mainFrom now on you can pull and push between your local repo and the remote.
Public vs Private Repositories
- Public repo
Anyone on the internet can see the code. Good for: - Open source projects
- Portfolio projects you want to show to employers
- Private repo
Only you and people you explicitly invite can see the code. Good for: - Commercial projects
- Experiments you are not ready to share
Both GitHub and GitLab support free private repositories for individuals.
Branches and Pull / Merge Requests
You already know Git branches. The hosting platforms add collaboration workflows on top.
Feature Branches
Common pattern:
- You create a branch locally:
git checkout -b feature/add-login- You make changes and commit:
git commit -am "Add basic login endpoint"- You push the branch:
git push -u origin feature/add-loginNow the branch exists on GitHub or GitLab and others can see it.
Pull Requests (GitHub) / Merge Requests (GitLab)
After you push a branch, you usually open a request to merge your changes into the main branch.
- On GitHub, this is called a Pull Request (PR).
- On GitLab, this is called a Merge Request (MR).
They are conceptually the same.
Inside a PR/MR you can:
- See diffs (what changed)
- Add comments to specific lines
- Request reviews from team members
- Run automated tests (CI)
This is central to team development and code quality.
Issues and Project Management
Both platforms support issues which are like tickets or tasks.
Examples:
- "Bug: 500 error when updating user profile"
- "Feature: Add filtering to /tasks endpoint"
- "Refactor: Move database logic to repository layer"
You can:
- Assign issues to people
- Add labels (bug, enhancement, backend, urgent)
- Link issues to PRs/MRs
For backend projects, issues help you organize:
- API endpoints to implement
- Database migrations to design
- Performance bugs to fix
Both platforms also provide more advanced project management tools such as boards and milestones, useful for larger teams.
Wikis and Documentation
Both GitHub and GitLab can provide a wiki section for each repository.
You can document:
- API overview
- Architecture decisions
- Database diagrams
- Deployment steps
Although for many backend projects you will use Markdown files inside the repo (like README.md and docs/ folder), the built-in wiki can be helpful for teams.
GitHub Overview
GitHub is the most widely used Git hosting platform, especially in open source and many companies.
Key Concepts
User Accounts and Organizations
On GitHub you have:
- User account
Your personal profile, e.g.github.com/alex-backend. - Organizations
Shared spaces for teams or companies, e.g.github.com/acme-corp.
Repositories can live either:
- Under your user account:
github.com/alex-backend/my-api - Under an organization:
github.com/acme-corp/payment-service
For a backend developer:
- Your portfolio and side projects usually live in your personal account.
- Company projects are often in an organization.
Stars, Forks, and Watch
GitHub is very social, and you will interact with open source often.
- Star a repo to bookmark or show appreciation.
- Fork a repo to create your own copy under your account.
Example workflow to contribute to an open source backend library:
- Fork the repo.
- Clone your fork.
- Create a branch, make changes, push.
- Open a Pull Request from your fork to the original project.
This is how you might contribute to Python libraries, FastAPI, or any backend tool.
GitHub Pages
GitHub can host static sites from a repo. This is useful to:
- Host project documentation.
- Publish small dashboards or API documentation sites generated from your backend.
For backend documentation you might generate static docs (with tools like MkDocs or Sphinx) and serve them with GitHub Pages.
Creating and Connecting a Repository
Example: you want to put your first backend project on GitHub.
- Create a new repo on GitHub (via the website):
- Name:
task-manager-api - Choose public or private
- Do not initialize with README if you already have one locally.
- On your local machine, in the project folder:
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin git@github.com:your-username/task-manager-api.git
git push -u origin mainNow your API project is visible on GitHub. Employers and collaborators can see your code structure, tests, and documentation.
GitHub Actions (Overview Only)
GitHub provides GitHub Actions, a built-in CI/CD system. You will use CI/CD in a later chapter, so here just understand:
- You can define workflows in
.github/workflows/*.yml. - For backend projects, these workflows can:
- Run tests on each commit.
- Build Docker images.
- Deploy to servers or cloud platforms.
You do not need details here, just know that GitHub can automatically test and deploy your backend when you push code.
GitLab Overview
GitLab is both a SaaS platform like GitHub (gitlab.com) and a self-hosted product you can run on your own servers. Many companies use GitLab for its integrated toolset.
Hosted vs Self-Hosted
You can use:
- GitLab.com for cloud-hosted repos.
- GitLab CE/EE as an application installed on a company or private server.
Self-hosting is very common in organizations that want full control over their code and CI infrastructure, which is often important for backend systems with sensitive data.
Namespaces, Groups, and Projects
GitLab uses:
- User namespaces for personal projects.
- Groups for organizations, teams, departments.
A project in GitLab is similar to a repository in GitHub.
Examples:
- Personal project:
gitlab.com/alex-backend/url-shortener - Group project:
gitlab.com/acme-corp/billing/payment-service
Groups can also contain subgroups, which can help organize a microservices backend into separate projects.
Merge Requests and Code Review
In GitLab you open Merge Requests (MRs) to merge branches.
Typical backend team workflow:
- Developer creates a feature branch:
feature/add-user-roles- Developer pushes branch to GitLab.
- Developer opens a Merge Request:
- Source branch:
feature/add-user-roles - Target branch:
mainordevelop - CI pipeline runs tests.
- Reviewer checks code, adds comments, and approves.
- MR is merged.
The process is almost identical to GitHub Pull Requests, but the terminology is different.
GitLab CI/CD (Overview Only)
GitLab has built-in CI/CD configured with a .gitlab-ci.yml file in your repo.
Like GitHub Actions, GitLab CI/CD can:
- Run backend tests.
- Build Docker images.
- Deploy services to staging or production.
You will explore CI/CD in a dedicated chapter, but for now understand that GitLab is very strong in this area and many backend teams prefer it because everything is integrated.
GitHub vs GitLab: Practical Comparison for Backend Work
From a beginner backend developer point of view, both platforms can do almost everything you need. However, each has strengths.
High-Level Comparison
| Feature / Aspect | GitHub | GitLab |
|---|---|---|
| Popularity (open source) | Very high, default for many OSS projects | Used by many companies, less for public OSS |
| Account type | User + Organizations | User + Groups + Subgroups |
| Self-hosting | GitHub Enterprise (paid, less common for hobby) | Very common, free Community Edition available |
| Pull / Merge requests | Pull Requests | Merge Requests |
| CI/CD | GitHub Actions | GitLab CI/CD (very integrated) |
| Project management | Projects (classic and new), issues, milestones | Boards, epics, issues, milestones, advanced PM |
| Integration with external apps | Very large ecosystem | Good integration, especially around DevOps |
When You Might Prefer GitHub
- You are building a public portfolio as a beginner backend developer.
- You want to contribute to open source projects like FastAPI, Django, or libraries.
- You want recruiters or hiring managers to easily see your code.
Many companies also use GitHub internally, so learning GitHub is very useful.
When You Might Prefer GitLab
- Your company or client is already using GitLab.
- You need a self-hosted solution for security or compliance.
- You want integrated CI/CD, container registry, and project management in one place.
As a developer, you do not need to choose one forever. You can and probably will use both during your career.
Hosting Your First Backend Project
Let us walk through an example backend project and how you would use GitHub and GitLab in practice. This example is language and framework agnostic.
Example Project: "Notes API"
You build a simple REST API that:
- Creates, reads, updates, deletes notes.
- Stores notes in a PostgreSQL database.
- Has tests and basic documentation.
Structure Locally
Your local folder might look like:
notes-api/
app/
__init__.py
main.py
models.py
routes.py
tests/
test_notes.py
requirements.txt
README.md
.gitignoreYou initialize Git, commit, and everything works locally.
Publishing to GitHub
- Create a new repo on GitHub,
notes-api. - Add it as a remote and push as shown earlier.
Now on GitHub you can:
- Add a README that describes:
- How to run the API locally.
- How to run tests.
- Tag releases for stable versions, such as
v1.0.0. - Open issues for ideas or bugs.
- Invite collaborators.
Later, you can add a basic GitHub Actions workflow such as:
# .github/workflows/tests.yml
name: Run tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip install -r requirements.txt
- run: pytestWhenever you push, tests run automatically.
Publishing to GitLab
If you instead (or also) want to use GitLab:
- Create a project on GitLab,
notes-api. - Add the GitLab URL as another remote, or host there only.
git remote add gitlab git@gitlab.com:your-username/notes-api.git
git push -u gitlab mainOn GitLab you might add a minimal CI file:
# .gitlab-ci.yml
stages:
- test
test-backend:
stage: test
image: python:3.12
script:
- pip install -r requirements.txt
- pytestNow, every push to GitLab triggers tests there.
You could even use both GitHub and GitLab remotes if needed:
git remote -v
# origin git@github.com:your-username/notes-api.git
# gitlab git@gitlab.com:your-username/notes-api.gitThen:
git push origin main
git push gitlab mainThis is not common for production systems but can be useful if you want redundancy or use GitHub for portfolio and GitLab for CI.
Practical Tips for Beginners
Commit Messages and PR/MR Titles
Clear messages and request titles help maintain backend projects.
Examples of good commit messages:
Add POST /notes endpoint with validationFix 500 error when updating note without titleRefactor database session handling
Examples of good PR/MR titles:
Add pagination to GET /notesImplement JWT-based authenticationOptimize queries for notes listing
These make code history and reviews easier.
Protecting Main Branch
On both GitHub and GitLab you can protect your main branch so you:
- Cannot push directly.
- Must use PRs/MRs.
- Must pass tests before merge.
This is important for backend stability, especially once your API is deployed to production. Broken code in main can break real users.
Using Issues to Plan Backend Work
Break work into small, clear issues.
Example set of issues for a new feature:
- "Design database schema for tags"
- "Add models and migrations for tags"
- "Add CRUD endpoints for tags"
- "Add tests for tags API"
- "Update API documentation for tags"
Each issue can map to a branch and a PR/MR. This structure scales well as your backend grows.
Important Concepts to Remember
Key Points About GitHub and GitLab
- Both provide remote Git repositories, collaboration, and CI/CD integration.
- Use branches and Pull Requests / Merge Requests instead of committing directly to main.
- Choose public repos for portfolio and open source, private repos for proprietary or sensitive code.
- GitHub is dominant in open source and hiring visibility. GitLab is very strong for integrated DevOps and self-hosting.
- Use issues and project features to organize backend tasks and bugs.
By understanding GitHub and GitLab early in your backend journey, you prepare yourself to work effectively in almost any modern development team.
Views: 7
KAHIBARO