How to fix bash: git-receive-pack: command not found fatal: Could not read from remote repository. in Git

GitINTERMEDIATEMEDIUMUpdated Dec 6, 2025ยท 123 views

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.

Quick fix

Fixes bash: git-receive-pack: command not found fatal: Could not read from remote repository.

# 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-pack
  1. Verify git-receive-pack exists on the remote server
  2. Test the PATH in non-interactive SSH session
  3. Fix the PATH for non-interactive sessions (recommended solution)
  4. Configure Git to use explicit receive-pack path (quick workaround)
git โ€” error
# 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-pack
bash: git-receive-pack: command not found
fatal: Could not read from remote repository.

What this error means

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.

Typical symptoms

  • Git push fails with 'bash: git-receive-pack: command not found' error
  • Error followed by 'fatal: Could not read from remote repository'
  • Git commands work fine when logged into the server interactively
  • Issue occurs after setting up a new Git server or changing Git installation location
  • Error appears only over SSH, not with HTTP(S) protocol
  • Other Git operations like fetch or pull may also fail with similar errors about git-upload-pack

Common causes

  1. Git binaries are not in the PATH for non-interactive SSH sessions
  2. Shell configuration files (.bashrc, .bash_profile, .zshenv) not properly set up for non-interactive use
  3. Git installed in a non-standard location not included in default system PATH
  4. Git client configured with incorrect path to receive-pack on the remote
  5. Remote user's shell initialization differs between interactive and non-interactive sessions
  6. Git not installed on the remote server at all

How to fix "bash: git-receive-pack: command not found fatal: Could not read from remote repository."

1Verify git-receive-pack exists on the remote server

First, confirm that Git is actually installed and locate the git-receive-pack binary:

bash
# 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-pack

If 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.

2Test the PATH in non-interactive SSH session

Check what PATH is available when Git connects (non-interactive session):

bash
# See the PATH that non-interactive SSH sees
ssh user@remote-server "echo $PATH"

# Compare to interactive session
ssh user@remote-server
echo $PATH
exit

If 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.

3Fix the PATH for non-interactive sessions (recommended solution)

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:

bash
# SSH into the server
ssh user@remote-server

# Edit .bashrc
nano ~/.bashrc

Add or modify the PATH at the beginning of the file:

bash
# Add Git to PATH (adjust path as needed)
export PATH=/usr/bin:/usr/local/bin:$PATH

For Zsh users, use ~/.zshenv which is sourced for all sessions:

bash
# Edit .zshenv
nano ~/.zshenv

Add:

bash
export PATH=/usr/bin:/usr/local/bin:$PATH

After editing, test immediately without logging out:

bash
# 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.

4Configure Git to use explicit receive-pack path (quick workaround)

If you can't modify the remote server's shell configuration, tell Git the explicit path to git-receive-pack:

bash
# 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-pack

Replace /usr/bin/git-receive-pack with the actual path you found in step 1.

You can also configure this in .git/config manually:

ini
[remote "origin"]
    url = user@remote-server:/path/to/repo.git
    receivepack = /usr/bin/git-receive-pack
    uploadpack = /usr/bin/git-upload-pack

This 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.

5Install Git if missing

If git-receive-pack truly doesn't exist on the remote server, install Git:

Debian/Ubuntu:

bash
sudo apt-get update
sudo apt-get install -y git

RHEL/CentOS/Fedora:

bash
sudo yum install -y git
# or
sudo dnf install -y git

macOS:

bash
brew install git
# or install Xcode Command Line Tools
xcode-select --install

After installation, verify it's in the PATH:

bash
which git-receive-pack
6Verify the fix by pushing

Test that your fix worked:

bash
# 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 main

If successful, you should see the usual Git push output without the "command not found" error.

Advanced notes

### 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:

bash
# If not running interactively, don't do anything
[ -z "$PS1" ] && return

This 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:

bash
# On the remote server
git init --bare /path/to/repo.git

Trying to push to a non-bare repository will give different errors about updating checked-out branches.

Frequently asked questions

What does "bash: git-receive-pack: command not found fatal: Could not read from r" mean?
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.
How do I fix "bash: git-receive-pack: command not found fatal: Could not read from r"?
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.
What causes "bash: git-receive-pack: command not found fatal: Could not read from r"?
Git binaries are not in the PATH for non-interactive SSH sessions Shell configuration files (.bashrc, .bash_profile, .zshenv) not properly set up for non-interactive use Git installed in a non-standard location not included in default system PATH
Is the "bash: git-receive-pack: command not found fatal: Could not read from r" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading