How to resolve the Git issue - Ignoring dangling symref head

Last modified: May 24, 2024

The following error indicates that the symbolic reference (symref) HEAD is pointing to a reference that no longer exists or is not properly defined.

warning: ignoring dangling symref head
fatal: ambiguous argument 'head': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

To avoid this error, make sure you have created a local clone of your repository and made an initial commit using the following commands:

git commit --allow-empty -m initial

git push

You also need to make sure you have selected Git as the Source control system in the Source Control Repository Properties dialog.

Select the repository folder

You can also encounter this error when linking a different database using the same Source control settings. In that case, try linking your database anew with a different Repository name or Repository folder.

To automate the process of setting up a local Git repository for a database, you can also use the following script. It creates a folder to store the main repository and initializes it. Then, it creates a clone of this repository (because the Studio works only through a clone, not directly with local or remote repositories), makes an initial commit, and pushes it to the cloned folder.

:: Save this as a batch file in a folder that will store repositories.
:: Change DatabaseName to your database name; this will be the repository folder name.
set _database=DatabaseName
:: Change _main if desired; this will be the folder for the main repository.
set _mainfolder=_main
:: Please do not change the following variables and commands.
set _maindir=%_mainfolder%\%_database%

:: Create the main folder to store the main repository.
md %_mainfolder%
:: Create a subfolder under the main folder with the name of the database.
md %_maindir%
:: Navigate to the subfolder.
cd %_maindir%
:: Initialize the main repository (will be empty).
git init --bare

:: Go back to the root directory.
cd ..\..
:: Clone the main repository, creating a folder with the name of the database.
git clone %_maindir%
:: Navigate to the cloned folder.
cd %_database%
:: Run git commands in the cloned folder.
git commit --allow-empty -m initial
git push
set _path=%cd%
:: Print the repository folder for reference.
echo Cloned repo folder: %_path%
cd ..
:: In dbForge Studio, select the database, then use Source Control > Link database to Source Control.
:: Pick the Source Control repository as the cloned repository in the folder you created above.

pause

To further see how it works, refer to Link a database to Git.