Due to the project and time constraints, collaborative development cannot be avoided. Git version control tool is the best option for us.
Usually, remote git repositories can use GitHub. However, considering that the company project is not suitable for going public, I decided to set up a git server myself on Mac in the company LAN.
How to set up Git Server on Mac in LAN?
Here, I’m going to set up the Git server on Mac. You can refer the following article to install git on CentOS if you are using the Linux system.
Okay. Let’s go to set up a git server on Mac in LAN by the following steps.
Step 1: Add a new Account for the git server
Why do you need to create a new user?
Because the computer is used at the same time, if you log in as the git server, others can access all the information on your computer. The purpose of creating a new user is to isolate access. So, it’s better to add a new account for the git server.
It’s easy to add a new account on Mac, the steps as:
System Preferences-> Users & Groups-> Add a user account
Step 2: Login as the new user account to set remote login permissions
Setting remote login permissions on Mac as the following steps:
System Preferences-> Sharing-> Remote Login, then make sure the all users option is selected.
Step 3: Test if can access remotely
Then, you try to access the git server on other computers by ssh command as following. Note that you should input the password of the new user account.
ssh [email protected].1.108 Last login: Mon Feb 24 17:08:54 2020
By now, you can see that it’s ok to access remotely to the git server.
However, it needs to input the password each time when access to the git server. The more convenient solution is to add your ssh public key to the git server.
Step 4: Add ssh public key to the git server
As you know, everyone who remotely access the git server needs to add their ssh public key to the git server then no need to input the password when visiting the server. You can do that by the following steps.
a. To generate the ssh public key by command:
ssh-keygen -t rsa
The default path of the generated ssh public key is: ~/.ssh/id_rsa.pub.
b. Copy the content of ~/.ssh/id_rsa.pub file to the authorized_keys file in the path ~/.ssh/ on the git server. If there is no authorized_keys file in the path, then firstly to create one in the path.
Step 5: Setting a fixed IP for the git server
Generally, the IP of the LAN will be obtained again after booting the computer. If the IP is changed, the partner must change the remote address again.
So, it’s better to fix one IP for the git server. Step as System Preferences-> Network-> Advanced-> TCP/IP.
In the network setting panel, change the configure IPV4 to Using DHCP with manual address option.
Step 6:Create a git repository and test it
Build a folder to use as a git remote repository. Here I create a new folder on the desktop called w3c.git, usually, the repository name ends with .git
Then switch to this folder directory in the terminal and enter the command:
$ git init --bare Initialized empty Git repository in /Users/git/Desktop/w3c.git/
Now, it’s time to remotely access the git repository. On other computer’s terminal input the command to clone the git repository, and get the right info as following:
$ git clone [email protected]:Desktop/w3c.git Cloning into 'w3c'... warning: You appear to have cloned an empty repository.
When you see the above warning info, it means the git server has been set rightly.