Search code examples
gitshelldeploymentsshnon-interactive

How to deploy new code via git, if git only installed on my user?


The scenario

  • I have access to this old linux server, that no longer receives any type of updates. Only break and fix. There's no git installed on the server so I installed it locally on my user at ~/opt/bin. I added the directory to my path and for development on the server I can do pretty much everything I need to do with git.
  • I decided it would be cool to do my development on my workstation instead, and push to production code that is ready.
  • I set up a bare repository at my server, created a post-receive file with a checkout -f to my GIT_WORK_TREE and seems like everything is setup accordingly.

The problem

When I try to push my master branch, I get the following error:

 sh: git-receive-pack: command not found
 fatal: The remote end hung up unexpectedly

I know why this is happening. The $PATH on my SSH is only seeing /usr/bin:/bin:/usr/sbin:/sbin

My user is setup with a /bin/sh shell so using .profile/.bashrc/.bashprofile is not an option.

I can't use .ssh/environment either, because my PermitUserEnvironment is set to no.

I tried to create a hooks/pre-receive and set the path there, that did not work either.

Any idea on how to make SSH see git and get this working?

Thanks


Solution

  • I found it!

    http://www.wiredrevolution.com/git/fix-git-upload-pack-and-git-receive-pack-errors-on-shared-hosting

    The second solution involves adding the path to your git-upload-path and git-recieve-path in your local .git/config file under [remote "origin"]. This is the easiest method as you only have to make this change once.

    [remote "origin"]
    url = <repo address>
    fetch = +refs/heads/*:refs/remotes/origin/*
    uploadpack = <path to git-upload-pack>
    receivepack = <path to git-receive-pack>