Post date: Apr 29, 2020 5:3:17 PM
To install the git package on CentOS servers type:
sudo yum install git
Next, a git user as we’ll use that and the key to post to the server.
sudo useradd -r -m -U -d /home/git -s /bin/bash git
Lets create the git location for use later
sudo mkdir /opt/adxba/git
And lets give the git user permissions
sudo chown git:git /opt/adxba/git
Switch to user “git” using the su command:
sudo su - git
Run the following commands to create the SSH directory and set the correct permissions:
mkdir -p ~/.ssh && chmod 0700 ~/.ssh
Create a file named ~/.ssh/authorized_keys which will hold the authorized users’ SSH keys:
touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys
Then we we need to add the key to authorized_keys
nano /home/git/.ssh/authorized_keys
Paste your authorised key in that file and save
Lets see a password just in case we need it too
sudo passwd git
Set it to usual please.
That’s it. The server setup is complete.
OK, so lets use the location we created earlier as our git location. So lets change to that directory
cd /opt/adxba/git
We now need to create the git repository. I’m gonig to do it around the unity-api setup.
Run the following command to initiate a new empty repository:(make sure you change the name to be correct.)
git init --bare /opt/adxba/git/unity-api.git
Now for unity-api we need to do a hook so that it put the files in the correct place once the git is pushed. For that we need to create a file called a post-receive
nano /opt/adxba/git/unity-api.git/hooks/post-receive
We’re then going to add the directory that we want to copy the output to, for unity-api we also want to run composer install after each push just in case some of the dependencies change.
#!/bin/sh
GIT_WORK_TREE=/opt/adxba/unity/unity_api git checkout -f
cd /opt/adxba/unity/unity_api
composer install
OK Save that, then we need to make sure that the script is executable.
chmod +x /opt/adxba/git/unity-api.git/hooks/post-receive
And thats it!
Just in case its useful - Original Guide