The 'git-receive-pack: command not found' error occurs when the Git receive-pack binary cannot be found in the remote server's PATH during a push operation. This typically happens due to shell configuration differences between interactive and non-interactive SSH sessions.
The "git-receive-pack: command not found" error indicates that when you attempt to push to a remote Git repository over SSH, the remote server cannot locate the `git-receive-pack` command. `git-receive-pack` is a Git plumbing command that receives objects from `git push` and updates the remote repository. It's usually invoked automatically by the Git client when you run `git push`, but it must be available in the PATH of the remote user's non-interactive shell session. The key issue is that SSH sessions have different behavior for interactive logins (when you SSH in and get a shell prompt) versus non-interactive command execution (when Git runs commands over SSH). When you log in interactively, your shell typically sources files like `.bash_profile` or `.profile` that set up your PATH. However, when Git executes commands non-interactively, these files may not be sourced, leaving Git binaries out of the PATH. This explains why you might be able to run `git` commands just fine when SSH'd into the server, but `git push` fails with this error - they're using different shell configurations.
First, confirm that Git is actually installed and locate the git-receive-pack binary:
# SSH into the server and check if git-receive-pack exists
ssh user@remote-server "which git-receive-pack"
# If that returns nothing, try finding it
ssh user@remote-server "find /usr -name git-receive-pack 2>/dev/null"
# Common locations include:
# /usr/bin/git-receive-pack
# /usr/local/bin/git-receive-pack
# /opt/git/bin/git-receive-packIf which returns a path, note it down - you'll need it for the workaround. If nothing is found, Git is not installed on the remote server.
Check what PATH is available when Git connects (non-interactive session):
# See the PATH that non-interactive SSH sees
ssh user@remote-server "echo $PATH"
# Compare to interactive session
ssh user@remote-server
echo $PATH
exitIf the non-interactive PATH doesn't include the directory where git-receive-pack is located, that's your problem. The PATH typically needs to include /usr/bin, /usr/local/bin, or wherever Git is installed.
The best fix is to ensure Git is in the PATH for non-interactive shells. The method depends on your shell:
For Bash users, add the PATH to ~/.bashrc near the top, before any interactive-only checks:
# SSH into the server
ssh user@remote-server
# Edit .bashrc
nano ~/.bashrcAdd or modify the PATH at the beginning of the file:
# Add Git to PATH (adjust path as needed)
export PATH=/usr/bin:/usr/local/bin:$PATHFor Zsh users, use ~/.zshenv which is sourced for all sessions:
# Edit .zshenv
nano ~/.zshenvAdd:
export PATH=/usr/bin:/usr/local/bin:$PATHAfter editing, test immediately without logging out:
# From your local machine, test non-interactive PATH
ssh user@remote-server "which git-receive-pack"This should now return the path to git-receive-pack.
If you can't modify the remote server's shell configuration, tell Git the explicit path to git-receive-pack:
# One-time use for a single push
git push --receive-pack=/usr/bin/git-receive-pack origin main
# Or configure it permanently for the remote
git config remote.origin.receivepack /usr/bin/git-receive-packReplace /usr/bin/git-receive-pack with the actual path you found in step 1.
You can also configure this in .git/config manually:
[remote "origin"]
url = user@remote-server:/path/to/repo.git
receivepack = /usr/bin/git-receive-pack
uploadpack = /usr/bin/git-upload-packThis workaround is useful when you don't have the ability to modify shell configuration on the remote server, but it needs to be done for each repository clone.
If git-receive-pack truly doesn't exist on the remote server, install Git:
Debian/Ubuntu:
sudo apt-get update
sudo apt-get install -y gitRHEL/CentOS/Fedora:
sudo yum install -y git
# or
sudo dnf install -y gitmacOS:
brew install git
# or install Xcode Command Line Tools
xcode-select --installAfter installation, verify it's in the PATH:
which git-receive-packTest that your fix worked:
# Try pushing to the remote
git push origin main
# Or if you set up a new remote
git remote add origin user@remote-server:/path/to/repo.git
git push -u origin mainIf successful, you should see the usual Git push output without the "command not found" error.
### Understanding Interactive vs Non-Interactive Shells
When you SSH into a server and get a prompt, you're starting an interactive login shell. This typically sources:
- /etc/profile
- ~/.bash_profile (or ~/.profile, ~/.bash_login)
When Git runs commands over SSH (like git push), it starts a non-interactive non-login shell, which typically sources:
- /etc/bash.bashrc (system-wide)
- ~/.bashrc (user-specific)
However, many .bashrc files have a guard at the top that exits early for non-interactive sessions:
# If not running interactively, don't do anything
[ -z "$PS1" ] && returnThis guard causes everything below it to be skipped for non-interactive sessions. Your PATH configuration must be above this line to work with Git over SSH.
### For Zsh Users
Zsh is more predictable - it sources ~/.zshenv for all sessions (interactive, non-interactive, login, non-login), making it the ideal place for PATH configuration.
### HTTP/HTTPS vs SSH
This error only occurs with SSH remotes (URLs like user@host:repo.git or ssh://user@host/repo.git). If you use HTTPS remotes (https://host/repo.git), you won't encounter this issue because the server uses a different protocol that doesn't rely on the user's shell PATH.
### Git Daemon vs SSH
If you're setting up a Git server, you have alternatives to SSH:
- git-daemon: Lightweight read-only or read-write protocol (port 9418)
- HTTP(S) with git-http-backend: Works through a web server
- SSH: Most common, works everywhere, uses existing SSH authentication
SSH is popular because it requires no additional setup beyond SSH access, but it does have this PATH gotcha.
### Windows Git Servers
On Windows, when using Git over SSH (often with tools like Git for Windows or WSL), you need to add the Git installation directory to the Windows System Environment Variables PATH, not just User PATH. The SSH server service needs to see Git in its PATH.
### Bare vs Non-Bare Repositories
This error occurs when pushing to bare repositories (the typical setup for a central Git server). The remote repository should be initialized as bare:
# On the remote server
git init --bare /path/to/repo.gitTrying to push to a non-bare repository will give different errors about updating checked-out branches.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git