Git Credentials

Back to SIG Tooling & Set Up Tutorials

Author: Alice Liquori

Date: 2023-06-22

Manually setting up credentials for HTTPS :git/url

Configuring Git to Persist Credentials

git config --global credential.https://gitlab.sig-gis.com.useHttpPath true
git config --global credential.https://gitlab.sig-gis.com.helper store

After running these commands, changes should be observable in `~/.gitconfig`.

Creating Project Access Tokens

This can be done by visiting the "Access Tokens" subsection of your repository settings. The token you create should be made at Reporter level, with the `read_api` and `read_repository` scopes.

Manually Installing Project Access Tokens

After creating your token, you can store it on your deployment machine as the `sig-app` user with a command of this shape.

echo -e "url=https://sig-app:$TOKEN@gitlab.sig-gis.com/sig-gis/$REPO.git\n" | git credential approve

At this point, your credentials should be recorded in `~/.git-credentials`.

Cloning over HTTPS

After configuring your access token, you should now be able to clone your private repository over HTTP.

git clone https://gitlab.sig-gis.com/sig-gis/$REPO.git

Automatically generating and installing Project Access Tokens

I have written a short bash script that can be placed on a remote server to automate this process. It depends on the `jq` tool.

install-tokens.sh

This can be saved as `install-tokens.sh` on a remote server. Below is an example of how to use it.

./install-tokens.sh matryoshka cljcall runway-scripts