Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push error git-receive-pack

Tags:

git

I have two git repositories on different networks. I had been communicating between the two of them without problem but for some reason today when I am doing a "git push", I am getting the following error:

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

I googled and made sure that the "/usr/local/bin" was in my "$PATH". Here is the output of the bin directory of my git:

[pradeep@laptop ]$ls -l /usr/local/git/bin/
total 16760
-rwxr-xr-x  1 root  wheel  4329416 Mar 26 20:06 git*
-rwxr-xr-x  1 root  wheel    14852 Mar 26 20:06 git-credential-osxkeychain*
-rwxr-xr-x  2 root  wheel   162402 Mar 26 20:06 git-cvsserver*
lrwxr-xr-x  1 root  wheel        3 Apr  3 11:02 git-receive-pack@ -> git
-rwxr-xr-x  2 root  wheel  1830248 Mar 26 20:06 git-shell*
lrwxr-xr-x  1 root  wheel        3 Apr  3 11:02 git-upload-archive@ -> git
-rwxr-xr-x  2 root  wheel  1893064 Mar 26 20:06 git-upload-pack*
-rwxr-xr-x  1 root  wheel   333121 Mar 26 20:06 gitk*

Any ideas what might be going wrong?

Thanks

-------------- Edit ------------------- I have the following line in the ".bashrc" of my remote system:

export PATH=$LOCAL/git-1.8/bin/:$PATH

This is the output on the remote machine:

$ls $LOCAL/git-1.8/bin
git  git-cvsserver  gitk  git-receive-pack  git-shell  git-upload-archive  git-upload-pack

And this is the output when I do "ssh user@remote env" from my machine to the remote machine:

[pradeep@laptop ~]$ssh [email protected] env
SHELL=/bin/bash
SSH_CLIENT=153.133.52.171 52379 22
USER=k00603
MAIL=/var/mail/k00603
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/openssh/bin
PWD=/volume2/home/hp120242/k00603
SHLVL=1
HOME=/home/hp120242/k00603
LOGNAME=k00603
SSH_CONNECTION=153.133.52.171 52379 10.7.160.4 22
LC_CTYPE=en_US.UTF-8
_=/bin/env

The git path is missing in the bash.

Edit: The following is the ".bash_profile" in the home directory of my remote system:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:$LOCAL/git-1.8/bin

export PATH
like image 393
Pradeep Kumar Jha Avatar asked Apr 03 '13 02:04

Pradeep Kumar Jha


Video Answer


1 Answers

When you ssh into a box and get a prompt, you're actually going through a slight different process than when running a command. Shells have rules about what configuration gets sourced based on whether it's a login shell and/or if it's an interactive session. Try running:

ssh user@host env

This will print your environment as seen by a non-interactive login session. My guess is that /usr/local/git/bin is not on the path in this scenario. You can work around this by using the --receive-pack option for git push:

git push --receive-pack=/path/to/git-receive-pack

/path/to/git-receive-pack is the path on the remote machine. It tells git where to find the other end when ssh'ing into the remote.

The best answer is to fix your shell configuration, but that can be tricky depending on the shell. I mainly use ZSH, and I fix this by setting up a ~/.zshenv, which gets sourced by ZSH in a non-interactive shell. I think things tend to be less clear with bash. You may have to edit your ~/.bashrc and/or your ~/.bash_profile.

Assuming you have a vanilla Linux installation on the remote end (which is probably the case), and that it's running the bash shell, the easiest fix is to change your .bashrc. Edit ~/.bashrc, and add:

export PATH=/path/to/your/installed/git/bin:$PATH

Where /path/to/your/installed/git/bin is where you installed git in your home directory. I tend to put local installs in ~/.local/bin, so mine would look like:

export PATH=$HOME/.local/bin:$PATH

Your's may simply be:

export PATH=$HOME/bin:$PATH

You don't say the location, so I can't give you the correct formulation.

On most systems, .bashrc is sourced even when a command is provided to ssh. After you make this change, try running ssh user@host env again. You should see your the location of the bin folder holding the git binary in the path variable. You should then be able to do something like ssh user@host git --version and see something like:

git version 1.8.2

If you see an error, then you likely didn't type the path correctly, or .bashrc isn't being picked up when you ssh into the machine.

Sample .profile

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

Automatically using --receive-pack

Assuming your remote is named origin, you can do this:

git config --local remote.origin.receivepack \
    /path/to/git-receive-pack/on/the/remote

You may need to fix upload pack as well:

git config --local remote.origin.uploadpack \
    /path/to/git-upload-pack/on/the/remote
like image 154
John Szakmeister Avatar answered Oct 31 '22 01:10

John Szakmeister