Software Manufacturing

Ruǎnjiàn Zhìzào

Install a Git Server on a Raspberry Pi 5

Works on Raspberry Pi bash

Path Command Description
git@gitserver:~ $ sudo apt install git-core Logged in as root: install git.
git@gitserver:~ $ sudo mkdir /srv/git Create a directory you will put the git repositories in.
git@gitserver:~ $ sudo adduser git Add a new user with the new user with the name git. If you just use your git server locally, you can use git as password (if you care about security, use a password with at least 20 digits, use lower and upper case characters, special characters and numbers and do not write it down. Then, in case you can't remember after a few months, security is perfect, not even you will be able to access your code...).
git@gitserver:~ $ sudo chown git:git /srv/git Change ownership of the /srv/git directory to user git and group git.
git@gitserver:~ $ su git Switch the current user from root to git.
git@gitserver:~ $ cd /srv/git Change directory to /srv/git.
git@gitserver:/srv/git $ mkdir git_server_test_repository.git Create a directory you will put a test git repository into. This repository is not used for a real project, but used to test connectivity etc. You can always push stuff into it just for testing purposes, without affecting the repository of a real repository.
git@gitserver:/srv/git $ cd git_server_test_repository.git Change directory to the git repository directory.
git@gitserver:/srv/git/git_server_test_repository.git $ git init --bare Initialize the git repository as a bare (server) repository.

Create a Git Repository on your developer machine

Works on Windows PowerShell 7

Path Command Description
D:\Repos mkdir ProjectDirectory Create a project directory.
D:\Repos cd ProjectDirectory Go to the project directory.
D:\Repos\ProjectDirectory dotnet new gitignore Use a ".gitignore" file so that only relevant files are checked in. You need to have dotnet installed, because git lacks a "git new gitignore" command that adds a default ".gitignore" file. You can add an empty one, but that won't help you anything. You can also search the internet to find some random language or project specific ".gitignore" file. Sigh.
D:\Repos\ProjectDirectory git init Put the content of the C:\Repos\ProjectDirectory under Git version control.
D:\Repos\ProjectDirectory git add . Stage all the files (except the ones ignored due to ".gitignore"), so that these can be commited afterwards.
D:\Repos\ProjectDirectory git commit -m "Intial version." Create a new version (locally). Write as a message whatever you like (here, "Initial version" has been selected as the commit message).

Access your git repository on the server

Works on Windows PowerShell 7 (this is overcomplicated. The chances are high, that you won't be able to access your git server, which is by design. The reason is that it is very secure, if even you can't access it. Sigh.)

Path Command Description
C:\ cd C:\Users\DeveloperName\.ssh Go to your .ssh directory.
C:\Users\DeveloperName\.ssh if no id_rsa.pub is present: ssh-keygen -t rsa Check if C:\Users\DeveloperName\.ssh contains a id_rsa.pub
C:\Users\DeveloperName\.ssh cat ~/.ssh/id_rsa.pub | ssh git@gitserver.local "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" Copy your local public SSH key to the authorized_keys on the Git server. Afterwards, you do not have to type the Git password anymore, when pushing to the server.

Log in to your Raspberry Pi Git server

Works on Windows PowerShell 7

Path Command Description
D:\Repos\ProjectDirectory ssh git@gitserver Logging in to the Git server for the first time is a nightmare. Just finding the name or Internet Protocol address of your Raspberry Pi is painful. Then you have several options to be able to use it (password or certificate or other overcomplicated procedures, you may spend hours figuring it out). I can't add a description, because it would be too long and too complicated. Sigh.

Create a Git Repository on your Raspberry Pi Git server

Works on Raspberry Pi bash

Path Command Description
git@gitserver:~ $ cd /srv/git Go to the git directory. You may have to create this directory first (or you may choose to place your Git repositories somewhere else, there is no standard). Sigh.
git@gitserver:/srv/git $ mkdir ProjectDirectory.git Create a project directory on the server. The extension .git is commonly used.
git@gitserver:/srv/git $ cd ProjectDirectory.git Go to the project directory.
git@gitserver:/srv/git/SoftwareManufacturing.git $ git init --bare Create a git repository (a bare one, because this is our server repository). We will just push and pull commits to and from the server. We will not create commits on the server directly. Ignore hints about the initial branch name. Sigh.
git@gitserver:/srv/git/SoftwareManufacturing.git $ exit Logout from the server.

Push the local changes to the Raspberry Pi Git server

Works on Windows PowerShell 7

Path Command Description
D:\Repos\ProjectDirectory git remote add origin git@gitserver:/srv/git/ProjectDirectory.git Connect the local git repository to the server git repository. What user to use on the server is not clear to me, I have just used a separate user git, instead of root, which complicates the whole thing (e.g. if you log in with a different user than the one that created any of the the /srv/git/SoftwareManufacturing.git subdirectories). Sigh.
D:\Repos\ProjectDirectory git push --set-upstream origin master The first time, you can't just use "git push" but you have to provide the upstream branch of your local branch. Sigh.
D:\Repos\ProjectDirectory git push From then on, you can just use "git push".

Work as usual

Works on Windows PowerShell 7

After so many steps, you are now ready to work just "as usual".

Path Command Description
D:\Repos\ProjectDirectory git add . Stage all the files (except the ones ignored due to ".gitignore"), so that these can be commited afterwards.
D:\Repos\ProjectDirectory git pull If you are working together with other people on the same code (don't do it unless really necessary, because it complicates things, you will spend some time with "merging" changes from different persons instead of working productively), get the latest version from the server first.
D:\Repos\ProjectDirectory git commit -m "Add some changes." Create a new version (locally). Write as a message whatever you like (what you did in imperative present tense is recommended). There is no standard. Sigh.
D:\Repos\ProjectDirectory git push Push the commit to the server.

Tag a commit

Works on Windows PowerShell 7

If you want to tag a commit (e.g. for each version that is used outside the development team).

Path Command Description
D:\Repos\ProjectDirectory git tag -a v1.2.3.4 -m "Version 1.2.3.4." Add an (annotated) tag locally.
D:\Repos\ProjectDirectory git push origin v1.2.3.4 Push the tag to the Git server.