Categories
Git

Build git server

For Debian,

sudo apt update && sudo apt install git

For centos,

sudo yum install git
sudo useradd -r -m -U -d /home/git -s /bin/bash git
sudo su - git
mkdir -p ~/.ssh && chmod 0700 ~/.ssh
touch ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys
git init --bare ~/reponame.git

Git server is ready!

Pushing and Pulling from Local

On the LOCAL

cat ~/.ssh/id_rsa.pub

Add the above id_rsa.pub file content from LOCAL to below authorized_keys file ON THE SERVER

sudo nano /home/git/.ssh/authorized_keys

Create a LOCAL repo

cd /path/to/local/repo
git init .
git remote add origin git@SERVER_IP_ADDRESS:reponame.git
touch test_file
git add .
git commit -m "initial commit"
git push -u origin master