How to add personal git repository in a web hosting server

The most useful site for the topic is

If your web hosting server does not have git, you can just manually install the git. (I don’t want to describe this at this posting.)

1. Prerequisite

Check following CLI commands are available in the server


2. The goal

Here is the one that I want to achieve.

  • ${HOME}/git_projects in the server
    • This is the actual git repositories such as xxx.git, yyy.git, etc.
  • ${HOME}/public_html/git in the server
    • This is the http address that a user can access
  • A user can use the http address with proper userID and password

3. ${HOME}/git_projects in the server

Do this:

cd ${HOME}/git_projects
mkdir xxx.git
cd xxx.git
git init --bare --shared=all
touch git-daemon-export-ok

Now, the xxx.git is ready to use.

4. ${HOME}/public_html/git in the server


Options +ExecCgi
AuthName "Private Git Access"
AuthType Basic
AuthUserFile ${HOME}/public_html/git/.htpasswd
Require valid-user
RewriteEngine on
RewriteBase /
SetHandler cgi-script
RewriteRule ^([a-zA-Z0-9._]*\.git/(HEAD|info/refs|objects/(info/[^/]+|[0-9a-f]{2}/[0-9a-f]{38}|pack/pack-[0-9a-f]{40}\.(pack|idx))|git-(upload|receive)-pack))$ ./$1

#first we export the GIT_PROJECT_ROOT
export GIT_PROJECT_ROOT=${HOME}/git_projects
#and run your git-http-backend

#uncomment the following line if you want to see environment variable values

The should have +x permission.


You need to create it by yourself. is a good site to create the .htpasswd.

5. Client

Create a directory and get the repository. And, git push at the end. Here is showing an example.

mkdir ~/tmp
cd ~/tmp
git clone http://[ID]
cd xxx
...(modify or add files)
git add .
git commit -m "Initial Commit"
git push origin master

Note that “git clone http://[ID]” will ask you password.

Also, after this, other user can clone the repository by git clone http://[ID] in anywhere, and “git push” and “git pull” can be used.

6. Other notes

From time to time, you may encounter 403 error. In this case, you need to check .htaccess in the root web site directory (normally, ~/public_html/.htaccess) to check if it has like this:

<Limit GET POST>
order deny,allow
deny from all
allow from all

2 Replies to “How to add personal git repository in a web hosting server”

  1. This is the post just what I was looking around and finally I’ve get here. I will make a discussion with my boss about this issue for understanding perfectly but thanks a lot for sharing this precious allocation very wisely. Keep it up.

Leave a Reply

Your email address will not be published. Required fields are marked *