Summary
Steps on how to install and configure a git server in Ubuntu Server 22.04 running on a Raspberry Pi (RPI).
Initial
Assumes that Ubuntu 22.04 is correctly installed on the RPI, see How to: Ubu on RPI. Note you can also test this out on a VirtualBox VM see How to: Ubu Server on VBox.
server info
- choose a tag for the location of the git server: e.g. git_svr
- choose a git password: git_password
setup SSH
on client:
ssh-keygen -C "git_svr rsa" -f ~/.ssh/git_rsa
# use "git_rsa" as file
on server:
sudo adduser git
sudo usermod -aG sudo git
su git
cd # go home
mkdir ~/.ssh && touch ~/.ssh/authorized_keys
on client:
cat ~/.ssh/git_rsa.pub | ssh git@git_svr "cat >> /home/git/.ssh/authorized_keys"
on server:
cat ~/.ssh/authorized_keys # confirm key was set in authorized_keys
Create a git project
cd ~ # ensure at git home
git init --bare project1.git # create test project
on client:
git clone git@git_svr:project1.git
cd project1
# add file x.txt
git add .
git commit -m "testing git"
git push
# change x.txt
git add .
git commit -m "testing git2"
git push
on server:
# assume "git" userid
cd ~
ll project1.git
git@git_svr:~/project1.git$ ll
total 40
drwxrwxr-x 7 git git 4096 Apr 1 19:52 ./
drwxr-xr-x 5 git git 4096 Apr 1 19:48 ../
drwxrwxr-x 2 git git 4096 Apr 1 19:48 branches/
-rw-rw-r-- 1 git git 66 Apr 1 19:48 config
-rw-rw-r-- 1 git git 73 Apr 1 19:48 description
-rw-rw-r-- 1 git git 23 Apr 1 19:48 HEAD
drwxrwxr-x 2 git git 4096 Apr 1 19:48 hooks/
drwxrwxr-x 2 git git 4096 Apr 1 19:48 info/
drwxrwxr-x 10 git git 4096 Apr 1 19:52 objects/
drwxrwxr-x 4 git git 4096 Apr 1 19:48 refs/
Automate new project creation
on client:
# use ssh to invoke the git init on the server
ssh git@git-svr 'git init --bare project2.git'
git clone git@git_svr:project2.git
cd project2
Clean up all previous commits in a repo
At times, it is useful to clean up previous commits.
on client: clean up previous commits
git branch cleaned $(echo "cleanup commits" | git commit-tree HEAD^{tree})
git branch -m master old-master
git branch -m cleaned master
git checkout master
git branch -D old-master
git gc --aggressive --prune=all
git repack -a -d -f --depth=250 --window=250
git push --force origin master
# show there's only one commit
git log --oneline
- note that this reduces the space on working directory but not on the git server
- run this command to reduce (some of) the space on the server:
git repack -a -d -f --depth=250 --window=250