Gitblit

From regional-training

This is a pure Java implementation of git

Dependency

The java JDK 1.8 is required for nexus (and potentially gitblit). There are several sources, that I have tried over time. Initially ubuntu had a nice release and so does adoptopenjdk - which is the release I use now. Every now an then a security update will zap the Java configuration on server.server and this is how you can fix it. It may only ve necessary to run

update-alternatives --config java

to fix the problem.

The following instructions work [1] as root:

  • obtain the GPG key
curl --silent https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
  • include the apt source
cat <<EOF | sudo tee -a /etc/apt/sources.list.d/adoptopenjdk.list
deb https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ $(lsb_release  --codename --short) main
EOF
  • locate
apt-cache search adoptopenjdk
  • install
apt install adoptopenjdk-8-hotspot
  • now fix the alternates
update-alternatives --config java

used to work

  • requires an older JDK (or seems to; will try openjdk-11-jre later)
  • conveniently ubuntu and nvidia have an nvidia-openjdk-8-jre (which seems to work)
  • modify your /etc/apt/sources.list
deb [trusted=yes] http://archive.ubuntu.com/ubuntu buster universe
deb-src http://archive.ubuntu.com/ubuntu buster universe
  • update
sudo apt update
  • install openjdk-8-jre
sudo apt install nvidia-openjdk-8-jre

Installation

  • create an /opt/gitblig
sudo mkdir /opt/gitblit
  • create a gitblit user
sudo useradd gitblit
  • fix their home directory ... vi /etc/passwd
/opt/gitblit
cd /opt
sudo wget http://dl.bintray.com/gitblit/releases/gitblit-1.8.0.tar.gz
  • extract
sudo tar -xvf gitblit-1.8.0.tar.gz
  • place in /opt/gitblit
sudo mv gitblit-1.8.0/* /opt/gitblit
  • cleanup
sudo rm gitblit-1.8.0
  • change ownership
sudo chown gitblit.gitblit gitblit
  • preserve the defaults
sudo cp /opt/gitblit/data/defaults.properties /opt/gitblit/data/defaults.properties-back
  • edit the defaults
sudo vi /opt/gitblit/data/gitblit.properties
  • modify and alter or disable some ports
git.repositoriesFolder = /mnt/repos/git
git.sshPort = -1
git.sshAdvertisedPort = -1
git.acceptedPushTransports = HTTP
  • wire in JAVA_HOME in cases where you have multiple JRE/JDK installed
sudo vi gitblit.sh
  • insert before the launch
export JAVA_HOME=/usr/lib/jvm/nvidia-java-8-openjdk-amd64/
export PATH=$JAVA_HOME/bin:$PATH
  • run it up from the console to prove it
cd /opt/gitblit
sudo su gitblit
./gitblit.sh
^C  // to quit
  • Fix any errors

set up gitblit daemon

These are the old instructions:

  • install the service script
sudo cp service-ubuntu.sh /etc/init.d/gitblit
  • enable
sudo systemctl enable gitblit
  • start the service
sudo systemctl start gitblit 
  • observer
sudo systemctl status gitblit
  • Fix any errors.

systemd

I converted it to a systemd since Debian 10 and 11 prefer systemd and the above was not working due to access problems to gitblit.jar.

  • create a /opt/gitblit/gitblit.service
Unit]
Description=gitblit service
After=network.target
StartLimitIntervalSec=0
# ProtectHome=true

[Service]
Type=simple
Restart=always
RestartSec=1
User=gitblit
Group=gitblit
WorkingDirectory=/opt/gitblit
ExecStart=/opt/gitblit/gitblit.sh 
TimeoutStartSec=0
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
  • reload
systemctl daemon-reload
  • not enable
systemctl enable gitblit
  • start
systemctl start gitblit

Administration

Users are stored with data/users.conf in the following style:

[user "admin"]
    password = admin
    role = "#admin"
    role = "#notfederated"
    repository = RW+:repo1.git
    repository = RW+:repo2.git
  • login and create some users, and change the password of the administrator (you know where to look if you forget; and you can always run a maintenance script to update the database)

Notice the administrative drop-down menu which is activated by pressing the logged-in user photo (not installed yet).

  • alter the admin password
  • install your developers

Copying repositories

Git repositories are usually source compatible, which means you can copy the directories from one server to another and install them. When using gitblit we have the guarantee that the repository can be copied from a Windows box to a Linux box (or so I hope because that is what I am trying first).

  • shutdown the server
sudo systemctl stop gitblit
  • copy repositories to /mnt/repos/git/...
sudo cp -R your-repo to /mnt/repos/git/
  • chown the owner properly
sudo -R chown gitblit.gitblit /mnt/repos/git
  • restart
sudo systemctl restart gitblit
  • you should now see all your repositories, including the hierarchy if one existed.

Restoring files

It is very easy to delete a git file and then realise that you want to preserve its history and source and put it somewhere else.

You can browse the local git repository log to find out where you zapped it:

git log --diff-filter=D --summary

You can restore the entry from the chose log via

checkout <deleting-commit>~1 -- <file-path>  // where ~X is the number of commits prior to the deleting-commit

References

Tips

  • create a new repository from the administration console; place it into a separate area e.g. jitsi-snapshots
  • clone a remote repository
git clone url
  • update a working local repository
git fetch
  • push the local repository to a new remote (on our company repository server) e.g.
git push http://ralph@localhost:8080/r/jitsi-snapshots/jitsi.git master:master

categories