Setup a GIT server on macOS

Setup a GIT server on macOS

This article describe how install and setup a git server on macOS & Linux server. A alternive with Gogs & Gitea is discribe at the end on this post. This git server used only a ssh protocol (no https).

Monday 22 November 2021

  1. Install Git server
    1. On your mac & macOS Requirements
    2. On your Linux server
  2. Setting UP GIT server
    1. Add a GIT user account on Server machine
    2. Turn on the remote login for GIT user in Server machine
    3. Set up SSH on client machines
    4. Setting up client’s public keys in Server
    5. Making a bare repo on the server
    6. Using the GIT server
    7. How can I pull/push from multiple remote locations?
  3. Alternative
    1. Gogs
    2. Gitea

Install Git server

On your mac & macOS Requirements

  1. Homebrew must be installed on your server
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  2. Update Homebrew
    $ brew update
    
  3. git install
    $ brew install git
    

On your Linux server

Debian’s default repositories provide you with a fast method to install Git. Note that the version you install via these repositories may be older than the newest version currently available. If you need the latest release, consider moving to the next section of this tutorial to learn how to install and compile Git from source.

First, use the apt package management tools to update your local package index. With the update complete, you can download and install Git:

sudo apt update
sudo apt install git

You can confirm that you have installed Git correctly by running the following command:

git --version

With Git successfully installed, you can now move on to the Setting Up Git server section of this tutorial to complete your setup.

Setting UP GIT server

  1. Add a <GIT user> account on Server machine.
  2. Turn on the remote login for <GIT user> in Server machine.
  3. Creating SSH keys in client machines
  4. Adding up client’s public keys in Server
  5. Making a bare repo on the server
  6. Using the new GIT server!

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

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.

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.

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.

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

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

How can I pull/push from multiple remote locations?

Reproduced here:

git remote set-url origin --push --add <a remote>
git remote set-url origin --push --add <another remote>

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.

I
macOS
Share it :