Git Push Fails with error about No such file or directory

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Problem

Trying to push a change with SourceTree in Bitbucket Server fails with the following error:

1 2 3 4 5 6 7 8 9 git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=manager-st push -v --tags origin develop:develop POST git-receive-pack (526 bytes) remote: hooks/pre-receive: line 9: C:\Program: No such file or directory Pushing to http://username@bitbucket.host/scm/proj/reponame.git To http://username@bitbucket.host/scm/proj/reponame.git ! [remote rejected] develop -> develop (pre-receive hook declined) error: failed to push some refs to 'http://username@bitbucket.host/scm/proj/reponame.git'

Diagnosis

Environment

  • This error is usually related to Windows platform.

Cause

The issue is caused by the presence of a space in the command path. This usually means that there is a space in $BITBUCKET_HOME.

This is also confirmed by an already existing bug report at BSERV-7859 - Space in STASH_HOME path causes push to fail after upgrade to Bitbucket Server.

The bug is closed as "Won't fix" due to the fact that Atlassian does not support Bitbucket installation with spaces in the $BITBUCKET_HOME path.

Solution

Workaround

In the example the $BITBUCKET_HOME directory is located in C:\Program Files\Atlassian\ApplicationData\Bitbucket.

Locate the problematic line

Locate the line in the hook that is generating the error:

1 2 3 4 5 6 7 8 9 10 #!/usr/bin/env bash #>******************************************************* # THIS FILE WAS AUTO-GENERATED BY ATLASSIAN STASH. # DO NOT MODIFY UNDER ANY CIRCUMSTANCE. #>******************************************************* if [[ "$OSTYPE" == "cygwin" ]]; then exec $(cygpath $STASH_HOOK_COORDINATOR) hooks/pre-receive.d "$@" <&0 >&1 2>&2 else exec $STASH_HOOK_COORDINATOR hooks/pre-receive.d "$@" <&0 >&1 2>&2 fi

In the example case the line is:

1 2 3 ... exec $STASH_HOOK_COORDINATOR hooks/pre-receive.d "$@" <&0 >&1 2>&2 ...

And the offending path is $STASH_HOOK_COORDINATOR that is translated into:

1 2 3 ... exec C:\Program Files\Atlassian\ApplicationData\Bitbucket\bin\git-hooks\hook-coordinator.sh hooks/pre-receive.d "$@" <&0 >&1 2>&2 ...

Modify the hook file

Modify the hook file to look like the following:

1 2 3 4 5 6 7 8 9 10 #!/usr/bin/env bash #>******************************************************* # THIS FILE WAS AUTO-GENERATED BY ATLASSIAN STASH. # DO NOT MODIFY UNDER ANY CIRCUMSTANCE. #>******************************************************* if [[ "$OSTYPE" == "cygwin" ]]; then exec $(cygpath $STASH_HOOK_COORDINATOR) hooks/pre-receive.d "$@" <&0 >&1 2>&2 else exec "C:\\PROGRA~1\\\\Atlassian\\ApplicationData\\Bitbucket\\bin\\git-hooks\\hook-coordinator.sh" hooks/pre-receive.d "$@" <&0 >&1 2>&2 fi

Restart Bitbucket

In same case a Bitbucket Server restart is needed in order to have the hooks work properly.

Resolution

Change the $BITBUCKET_HOME for your Bitbucket instance to a path without spaces to solve the issue without having to manually edit the hooks.

Updated on April 24, 2025

Still need help?

The Atlassian Community is here for you.