Importing commit history from GitLab to GitHub

GitHub Contribution Graph

Importing commit history from GitLab to GitHub


In this blog post, I will answer the question of how to enrich GitHub statistics to improve your job prospects by enriching your GitHub contribution graph.

GitHub After import-gitlab-commits

Problem

In interviews, people judge developers by their GitHub.Recently, I saw a tweet with a picture showing GitHub contributions with one commit of activity and the caption:

“Please don’t apply for a Senior dev position if your GitHub looks like this…”

Manuel Frigerio tweet about senior's GitHub

Manuel Frigerio tweet about senior's GitHub

There are many tools to fake GitHub history: 1 , 2 , 3 . But they create unreal commits, which is cheating. We need to find another way to enrich GitHub activity.

Resolution

You may remember that your company uses GitLab for day-to-day commits. Let’s export these commits to GitHub.

I use the tool import-gitlab-commits . It’s written in Go, very handy to run, and exports commits in an anonymized way to comply with NDA.

I will import my Clarity commits from their internal GitLab VCS clarity.gitlab.com . My GitHub statistics for 2020 before running import-gitlab-commits look like:

GitHub Before import-gitlab-commits

GitHub Before import-gitlab-commits

Step 1: Install import-gitlab-commits

First, let’s install Go and run the command:

go install github.com/alexandear/import-gitlab-commits@latest

Step 2: Execute import-gitlab-commits

Next, set the required environment variables:

export GITLAB_BASE_URL=https://clarity.gitlab.com
export GITLAB_TOKEN=your_secure_token
export COMMITTER_NAME="Oleksandr Redko"
export COMMITTER_EMAIL=oleksandr.red+github@gmail.com

where:

  • GITLAB_BASE_URL is a GitLab instance URL .
  • GITLAB_TOKEN is a personal access token . It will be used to fetch your commits from GITLAB_BASE_URL.
  • COMMITTER_NAME, COMMITTER_EMAIL are my GitHub name and email.

And run the command:

import-gitlab-commits

The tool will perform the following operations:

  1. Connect to GITLAB_BASE_URL using GITLAB_TOKEN and get my oredko user info.
  2. Fetch all GitLab projects that oredko contributed to.
  3. For all projects, retrieve the commits where the author is oredko.
  4. Create a new repo repo.clarity.gitlab.com.oredko on disk. Add new commits for all fetched info with the message Project: <PROJECT_ID> commit: <COMMIT_HASH> and committer Oleksandr Redko <oleksandr.red+github@gmail.com>:
Git Commit Anonymized Log

Git Commit Anonymized Log

Step 3: Create a GitHub repository and push to it

Finally, follow the guide and create a new GitHub repository called clarity-contributions.

Open the repo created by import-gitlab-commits and push to GitHub:

cd repo.clarity.gitlab.com.oredko
git remote add origin git@github.com:alexandear/clarity-contributions.git
git push

That’s it. My empty GitHub contribution graph from 2020 became full of commits:

GitHub After import-gitlab-commits

GitHub After import-gitlab-commits

Summary

In this article, I suggest a way to enrich GitHub activity by exporting real GitLab statistics. The import-gitlab-commits tool is a good solution for this purpose.


See also