Wednesday, February 12, 2014

Git protocol on server and client side

This is an advanced tutorial for experienced users that are familiar with git, SSH protocols and shell scripts.
 
On server side

[user@test_server ~]$ git daemon --base-path=/var/www/html --reuseaddr  --export-all --verbose --enable=receive-pack 

Do not close the terminal on server.
 --base-path=/var/www/html is path to your repository.
On developer side

[developer@dev_machine:~]$ mkdir repo
[developer@dev_machine:~]$ cd repo/
[developer@dev_machine:~/repo]$ git clone git://10.13.13.101/ project_folder
Initialized empty Git repository in /home/developer/repo/project_folder/.git/
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 9 (delta 1), reused 0 (delta 0)
Receiving objects: 100% (9/9), done.
Resolving deltas: 100% (1/1), done.
[developer@dev_machine:~/repo]$ cd project_folder/
[developer@dev_machine:~/repo/project_folder] (master)$ 


Once you are in project_folder you can push and pull to/from remote repository like this
[developer@dev_machine:~]$ git push git://10.13.13.101/ master:dev_mike

Or if you use SSH
[developer@dev_machine:~]$ git push ssh://user_name@10.13.13.101/var/www/html master:dev_mike
user_name@10.13.13.101's password:
or
Enter passphrase:

To start git daemon automatically when you login on the server do this:
[user@test_server ~]$ mkdir scripts
[user@test_server ~]$ cd scripts

Place the two following files in this folder

file:run_git_daemon:
#!/bin/bash
# chkconfig: 2345 20 80
gnome-terminal --working-directory="/home/user_name/scripts" --command="/home/user_name/scripts/git_server.sh"
exit 0

file:git_server.sh
#!/bin/bash
# run git daemon
git daemon --reuseaddr --base-path=/var/www/html --export-all --verbose --enable=receive-pack
Save files. Have your system administrator to place file run_git_daemon in auto start folder. Which folder? It depends of Linux distro.

Git server output in terminal window
Reboot machine, login in and you should see a terminal window (look image above)  opens with Ready to rumble in its first line. Once you make push, pull, fetch or clone the terminal window will show IP addressees that accessed the server and their tasks. Great for server tuning when you use git and/or SSH protocol.

No comments:

Post a Comment