Home VPN WorkPlace Web Sites/Apps Small Business Other Apps Contact Guides

Setup Your Git Server

Resource: https://thenewstack.io/how-to-set-up-the-http-git-server-for-private-projects/

HTTP

Install
sudo apt install nginx git fcgiwrap apache2-utils -y
Setup Git Storage Root
sudo mkdir /[rootdir]/git
Assign Ubuntu's www-data user to read/write on Storage Root
sudo chown -R www-data:www-data /[rootdir]/git
Configure NGINX
sudo nano /etc/nginx/sites-available/default
Locate
location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; }
Append Below (Update [rootdir])
location ~ (/.*) { client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this. auth_basic "Git Login"; # Whatever text will do. auth_basic_user_file "/[rootdir]/git/htpasswd"; include /etc/nginx/fastcgi_params; # Include the default fastcgi configs fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable fastcgi_param GIT_HTTP_EXPORT_ALL ""; fastcgi_param GIT_PROJECT_ROOT /[rootdir]/git; # /var/www/git is the location of all of your git repositories. fastcgi_param REMOTE_USER $remote_user; fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that. fastcgi_pass unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi }
The following should be returned
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Test Configuration
sudo nginx -t
Add User
sudo htpasswd -c /var/www/html/git/htpasswd user1
Restart NGINX
sudo systemctl restart nginx

Usage Example

Clone
git clone http://[url/ip]/[your_repo.git]
Or
git clone http://[username]@[url/ip]/[your_repo.git]

SSH

Pending Update

Setup Repository

Navigate to your git root
cd /[rootdir]/git
Create Reposity Directory
sudo mkdir [reponame].git
Enter New Directory
cd [reponame].git
Initialize New Repo
sudo git --bare init && sudo git update-server-info
Set Ownership
sudo chown -R www-data:www-data .
Set Permissions
sudo chmod -R 755 .