Setup a GIT server on macOS

This article describe how install and setup a Git server on macOS. A alternive with Gogs is discribe at the end on this post. This git
server used a ssh
protocol (no https
).
Monday 13 July 2020
1. Install Git via Homebrew
Requirements
- Homebrew must be installed on your server
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Update Homebrew
$ brew update
Now you can install git on your mac
brew install git
2. Setting UP a local GIT server
- Add a
<GIT user>
account on Server machine. - Turn on the remote login for
<GIT user>
in Server machine. - Creating SSH keys in client machines
- Adding up client’s public keys in Server
- Making a bare repo on the server
- Using the new GIT server!
1. Add a GIT user account on Server machine
Login to the admin account in mac. Open up System Preferences » Accounts
and add a standard user name git
2. Turn on the remote login for GIT user in Server machine
Log out of the git
user, and log back into your administrator account. Open up System Preferences » Sharing
and turn on Remote Login to allow ssh.
Set Allow access for to Only these users and the git
user to the list.
3. Set up SSH on client machines
Open a terminal on your local computer and enter the following cammand :
ssh-keygen -t rsa -C "your_email@example.com"
More informations are avalable in install-ssh-key-osx post.
4. Setting up client’s public keys in Server
Add the public key of the client machine to the authorized_keys
file on the server. Run this command on the client machine:
cat ~/.ssh/id_rsa.pub | ssh git@<git_server> "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
If you have more client machines, repeat the above steps in all of them.
5. Making a bare repo on the server
This is the definition of a bare
git repo: a repository that can never have files checked out. Everyone pulls and pushes from the server like normal, but nobody can actually work on the server (unless they make a non-bare clone).
If you are creating a new repository called myrepo.git
, you can make it bare like so:
git init --bare myrepo.git
6. Using the GIT server
In the client host all you have to do is clone your git repo.
git clone ssh://<git_user>@<git_server>/<git_path_server>/myrepo.git
Alternative
Gogs
A alternative is to install Gogs. Gogs is a painless self-hosted GIT
service. Gogs use the programming language Go. With Go, this can be done with an independent binary distribution across ALL platforms that Go supports (Linux, MacOS, Windows, ARM and more).
Gitea
A other alternative is Gitea. Gitea is a painless self-hosted GIT
service. It is similar to GitHub, Bitbucket, and GitLab. Gitea is a fork of Gogs. See the Gitea Announcement blog post to read about the justification for a fork.
The goal of this project is to provide the easiest, fastest, and most painless way of setting up a self-hosted Git service. With Go, this can be done with an independent binary distribution across all platforms and architectures that Go supports. This support includes Linux, macOS, and Windows, on architectures like amd64, i386, ARM, PowerPC, and others.
macOS