Setting a Git Server on a LAN

 

Instead of relying on a third party platform, if you have a spare linux server, it can be handy to setup your own local git server.

That means that you will not have to rely on github, or gitlab, and can perform your own lab, with versioning

On the server - let's call this host "myHub"

these steps will have to be done:

- installing ssh (openssh-server)

- installing git 

on the client machine a ssh public key will have to be generated using

- ssh-keygen -o

the key will be in ~/.ssh/id_rsa.pub and will need to be copied over the server as authorized.

https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols

Back to the local git server "myHub"

$ adduser git

$ su git

$ cd

$ mkdir .ssh

$ chmod 700 .ssh

$ touch .ssh/authorized_keys

the file is created with 0 in size (empty)

$ chmod 600 .ssh/authorized_keys

I recommend to copy and paste the key from the client into the server (in /tmp).

then append this file into the authorized_keys file

$ cat /tmp/id_rsa.pub >> authorized_keys

If you follow the video above, then you will have the git repositories inside the /var/www folder

#  mkdir project.git

# chown git:git project.git

$ cd project.git

$ git init --bare

that is done for the server side

Now on the client side

go to your source (or folder you want to push into the git server "myHub")

then add the git remote address

$ git remote add origin git@myHub:/var/www/project.git main

$ git push --set-upstream origin master:main

$ git log

on the first commit, you will have to declare the user.email and user.name (as global or local)

and from other machine to fetch the source

$ git clone git@myHub:/var/www/project.it -b main

 


To summarize "On server":
logged as user 'git'
$ mkdir project.git
$ cd my_project.git
$ git --bare init
 

"On client":
$ mkdir my_project
$ cd my_project
$ touch .gitignore
$ git init
$ git add .
$ git commit -m "Initial commit"
$ git remote add origin youruser@yourserver.com:/path/to/my_project.git
$ git push origin master


No comments:

Post a Comment

Related Posts with Thumbnails