2

I've been working on a project locally using git and laravel. I've finally decided to add a bare repo to our server in order to push the changes and automate deployment.

I'm sure I'm doing something wrong as I'm green to using git. When I do a push I get the following error:

stdin: is not a tty
bash: git-receive-pack: command not found
fatal: Could not read from remote repository

Please make sure you have the correct access rights and the repository exists.

Here's the process I used - keep in mind the project repository was initially cloned from laravel and I created my own master branch and a few pushes exist. I also have all ssh logging setup already.

  1. logged in via ssh
  2. created directory: mkdir public_html.git
  3. changed directory: cd public_html.git
  4. created the repo: git init --bare
  5. added a post-receive hook - which i verified works in a test project
  6. moved back to local machine
  7. added a new remote: git remote add www user@0.0.0.0:public_html.git
  8. made a new branch: git checkout -b develop
  9. attempted to push: git push www

Most of the research from looking into this mentions checking the git/config file, but all of that seems to be correct.

gin93r
  • 1,551
  • 4
  • 21
  • 39
  • Check the permissions on the directory on the server. The user specified in your git remote URL must have read/write permissions to that directory on the server. Second of all, you create a local branch, but in your push command you don't tell Git which branches to push. Instead, you want: `git push www -u develop` – Greg Burghardt Jan 29 '14 at 15:56
  • The group and owner are set to the user. I created it when logged in via ssh as that user. The permissions are 775 which seems adequate. It's my understanding that if you omit the branch from git push, it will use the current branch head. My active branch is develop, git push www should push the develop branch. I do notice you have a -u flag though... I don't see that in the docs. – gin93r Jan 29 '14 at 16:02

1 Answers1

3

It looks like git-receive-pack is not on the path for the user configuration used to push to the repository. When you push to a git repository via ssh git will use ssh to execute commands on the remote server under the user account which is doing the push. These commands, such as git-receive-pack, must be available on that user's path on the server. To diagnose this I would start by executing the command

ssh user@0.0.0.0 which git-receive-pack

You will almost certainly get a command not found error. Next you could try

ssh user@0.0.0.0 'echo $path' # Note the single quotes.

This will show you what the user's path is on the remote server and may help you figure out what is wrong. Note the line in the ssh man page:

ssh ... [user@]hostname [command]

...

If command is specified, it is executed on the remote host instead of a login shell.

This can be a subtle but important distinction as it means a login shell to the remote created with ssh user@0.0.0.0 may not see the same shell environment as a command run by ssh user@0.0.0.0 some remote command. This answer has an explanation of how this works for the bash shell, others behave similarly.

Community
  • 1
  • 1
asm
  • 8,758
  • 3
  • 27
  • 48
  • If I run `ssh user@0.0.0.0 which git-receive-pack` I receive `which: no git-receive-pack in (/usr/local/bin:/bin:/usr/bin)`. However, if I login via ssh first and then run it i get `/usr/local/cpanel/3rdparty/bin/git-receive-pack.` Running `ssh user@0.0.0.0 'echo $path'` I receive an empty returned line. – gin93r Jan 29 '14 at 16:33
  • I also did a comparison with another account, and noticed that the .bashrc was renamed to .bashrc_rm in that account. I did the same to this account. Without that filename changed, Running the 'echo $path' line above would result in a stdin: not a tty error. – gin93r Jan 29 '14 at 16:35
  • Ok - turns out the echo thing was due to '$path' vs '$PATH' Now - in my test account, I (who knows why) removed a file in my .ssh directory called "environment" - i'm now noticing that I'm getting the same errors while pushing to that account. So maybe I set the shell environment in that file? Does that sound right? Sorry, I'm green when it comes to this. If that is the case, how do I change it back? – gin93r Jan 29 '14 at 16:49
  • Ok that's what it was. I logged in via ssh, and ran `env > .ssh/environment` then restarted SSH. – gin93r Jan 29 '14 at 17:07
  • 1
    @Veo Okay, it looks like the default sshd setting is to deny this but if you're set up so that it works then that's a valid fix. – asm Jan 29 '14 at 17:09
  • [This answer](http://stackoverflow.com/questions/11128464/git-upload-pack-command-not-found) explains more detail. – gin93r Jan 29 '14 at 17:09
  • yes. I had set PermitUserEnvironment yes in /etc/ssh/sshd_config awhile ago and then dumped the env file in my test account before... just forgot about that. Thanks for your help. It ultimately led to the solution so have a check mark :) – gin93r Jan 29 '14 at 17:11