Search code examples
linuxgitapacherepositorysmart-http

Git + Smart Http(s): 403 Error


Although i have read many posts, I was not able to solve this problem.
I want to use Git + Smart Http, using a remote repository on my rasperry pi.
I'm running on Arch Linux.
First, let's consider an Http configuration (and not https), for semplicity.
Apache and Git are correctly installed on my Rasperry Pi, and the port for the Http connection is 8080.

On my Raspberry Pi:

1. I have uncommented in /etc/httpd/conf/http.conf the lines about mod_cgi, mod_alias, and mod_env

2. I have added to /etc/httpd/conf/http.conf these lines:

SetEnv GIT_PROJECT_ROOT /srv/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

<Directory "/usr/lib/git-core*">
    Require all granted
</Directory>
  1. I have created the directory /srv/git

    # mkdir -p /srv/git

  2. I have created and initialized a git repository:

    # mkdir -p /srv/git/test.git
    # git init --bare

  3. I have changed owner and group of the repo:

    # chown -R http:http /srv/git/test.git

On my client:

  1. I have cloned the repo inside the folder

    $ git clone http://address:8080/git/test.git

  2. I have created and added a new file and I have committed

    $ nano test.c
    $ git add test.c
    $ git commit -m 'first' 

  3. I have pushed the new project on my Rasperry Pi

    $ git push origin master

But I have this error:

atal: unable to access 'address:8080/git/test.git/';: The requested URL returned error: 403

Solution

  • If you clone the repo inside the test folder (in which you initialized a git repo), that means you have:

    test/test
    

    If you are pushing from the first test folder, that repo would not have any origin.

    Try in instead to remove any test folder, and start over with:

    git clone http://address:8080/git/test.git
    cd test
    # work
    git add .
    git commit -m "work"
    git push -u origin master
    

    Regarding the 403 error, I would recommand on the server Apache (2.4) side:

    <Directory "/usr/lib/git-core*">
       Options ExecCGI Indexes
       Order allow,deny
       Allow from all
       Require all granted
    </Directory>
    

    And:

    <LocationMatch "^/.*/git-receive-pack$">
        Options +ExecCGI
        Require all granted
    </LocationMatch>
    <LocationMatch "^/.*/git-upload-pack$">
        Options +ExecCGI
        Require all granted
    </LocationMatch>
    

    Also, on the server, in the git bare repo folder:

    cd /srv/git/test.git
    git config --file config http.receivepack true