1. Install git and apache
Open terminal and run commands:
$yum install httpd git
Start apache
$apachectl start
2. Create users file
/etc/git-users
username:password
othername:otherpassword
If you don't know how to create that file then install nano editor:
$yum install nano
and create file
$nano /etc/git-users
enter content and press Ctr + O to save, Ctr + X to exit.
3. Create folder that you want to push git base in
$mkdir /var/www/git
4. Create apache config file
/etc/httpd/conf.d/git.conf
SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
RewriteCond %{REQUEST_URI} /git-receive-pack$
RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]
<LocationMatch "/git">
Order Deny,Allow
Deny from env=AUTHREQUIRED
AuthType Basic
AuthName "Git Access"
AuthUserFile /etc/git-users
Require valid-user
</LocationMatch>
If you don't know how to find apache config folder, use this command
$apachectl -V
For example we found that apache config file in /etc/httpd/conf/httpd.conf
then we create file /etc/httpd/conf.d/git.conf
Restart apache
$apachectl restart
5. Create git base
$cd /var/www/git # folder that we created in step 3
$mkdir test.git
$cd test.git
$git init --bare --shared
Open config file
/var/www/git/test.git/config in git base then add this
[http]
receivepack = true
6. Using
Access git server via
http://your_server_ip_address/git/test.git with username and password set at step 2.