Using Git SSH with GitLab self-managed instances

Since GitLab Community Edition is open source, large projects like CMake may host their own self-managed GitLab instance. To make merge requests to such projects, one can configure Git SSH. For this example, we use Kitware’s CMake GitLab instance. This procedure works for any operating system, including Windows.

First, create an account on the self-managed GitLab instance and fork the desired repo. This will be available like

git clone https://gitlab.kitware.com/username/cmake

To git push using SSH, type:

git config --global url."ssh://gitlab.kitware.com/".pushInsteadOf https://gitlab.kitware.com/

Generate an SSH key–don’t reuse SSH keys between sites.

ssh-keygen -t ed25519 -f ~/.ssh/kitware

Go to the GitLab SSH Key page and add the contents of ~/.ssh/kitware.pub

Add to ~/.ssh/config:

Host gitlab.kitware.com
  User git
  IdentityFile ~/.ssh/kitware

Now checkout a new branch, make your changes according to Contributing.rst and submit a merge request.