How to integrate Gitlab Git repository into Redmine
Setting up the Redmine Git infrastructure

- Copy the access token to your clipboard and save it somewhere safe. You won’t be able to see it again.

The following is based on Redmine docker-compose config with Traefik & Let’s Encrypt
- Create a new directory to hold Git repositories for your Redmine instance.
create_redmine_git_dir.sh
mkdir redmine_git- Add that to the
docker-compose.ymlso it’s mapped inside the container
docker-compose.yml
services:
redmine:
# ...
volumes:
# ...
- './redmine_git:/git'Cloning a Gitlab repository into Redmine
Repeat this for every repository you want to integrate into Redmine.
- In Gitlab, open the project and goto
Settings->Access Tokens - Create an
Access Tokenwith the following settings:- You can name it
Redmine, but the name doesn’t matter, so feel free to choose any other name. - As
Role, selectDeveloper - As
Expiration Date, I recommend deleting the value by clicking thexicon, so the token never expires. Otherwise, you would have to regularly re-create tokens for all repositories. - As
Scopes, selectread_repositoryand nothing else.
- You can name it
- Now go to the project’s page on Gitlab and copy the Git URL, e.g.
https://gitlab.mydomain.com/myuser/MyProject.git - Edit that URL and add
username:password@afterhttps://with username being the name of the token (e.g.Redmine) and the password being the token you copied earlier.
repository_clone_url.txt
https://Redmine:[email protected]/myuser/MyProject.git- Now clone that URL as a mirror repository into the
redmine_gitdirectory
mirror_clone_repository.sh
cd redmine_git
git clone --mirror https://Redmine:[email protected]/myuser/MyProject.git- In redmine, navigate to the project you want to integrate the repository into, go into
Settings->Repositoriesand click onNew Repository:

- Enter the path to the repository, e.g.
/git/MyProject.gitand a new identifier which may contain only lowercase letters, numbers, and underscores. This identifier is used to reference the repository in Redmine’s database.

- Click on
Createand you’re done!
Setup automatic repository fetch
Redmine currently does not support fetching repositories automatically. You can set up a cronjob to fetch repositories every 5 minutes.
I recommend to use SystemD timers for this, as they are more reliable and generally more flexible than cronjobs.
In the directory where redmine_git resides, create a new file setup-git-fetch.sh, which sets up the fetch script and timer:
setup-git-fetch.sh
#!/bin/bash
export NAME=$(basename $(pwd))-gitfetch
cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'cd redmine_git && for i in *; do [ -d "\$i" ] && cd "\$i" && git fetch --all; cd ..; done'
WorkingDirectory=$(pwd)
EOF
cat >/etc/systemd/system/${NAME}.timer <<EOF
[Unit]
Description=${NAME} timer
[Timer]
OnCalendar=*:0/2
Persistent=true
[Install]
WantedBy=timers.target
EOF
# Enable and start service
systemctl enable --now ${NAME}.timerRun that script from the directory where redmine_git resides:
run_setup_git_fetch.sh
sudo bash setup-git-fetch.shThis script sets up a SystemD service and timer that fetches all repositories in redmine_git every 2 minutes.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow