Change to root GIT folder:
$ cd /var/GIT
Change permissions main folder project:
$ sudo chown -R oscargomezf:www-data project.git
$ sudo chmod 2775 *
Change others files and permissions inside the git project:
$ sudo chown -R oscargomezf:www-data project.git
$ sudo chmod 2775 *
$ cd project.git
$ sudo chmod 664 HEAD config description
$ sudo chmod 2775 branches hooks info logs objects refs
$ cd project.git/hooks
$ sudo chmod 775 *
$ cd project.git/info
$ sudo chmod 664 *
$ cd project.git/objects
$ sudo chmod 2775 *
$ cd project.git/objects/packs
$ sudo chmod 664 *
$ cd project.git/objects/info
$ sudo chmod 664 *
$ cd project.git/refs
$ sudo chmod 2775 *
$ cd project.git/refs/heads
$ sudo chmod 664
$ cd project.git/refs/tags
$ sudo chmod 664
REMOTE HEAD REFERS TO NONEXISTENT REF, UNABLE TO CHECKOUT
Check Existing Branches
After cloning the repository, list all available branches:
$ git branch -a
Look for the main branch (e.g., main or master). This is the branch you’ll want to check out.
Manually Check Out a Branch
If a branch exists, switch to it manually:
$ git checkout <branch-name>
For example:
$ git checkout main
This will resolve the issue if the main branch is present in the repository.
Set the Default HEAD on the Remote Repository
If you have admin access to the remote repository, configure the HEAD reference to point to the correct branch. Follow these steps:
Log in to the server where the repository is hosted.
Navigate to the .git directory:
$ cd /path/to/repository.git
Set the HEAD to the correct branch, e.g., main:
$ git symbolic-ref HEAD refs/heads/main
Clone a Specific Branch
If the remote repository's default branch isn't set correctly, you can directly clone a specific branch by using the -b option:
$ git clone -b <branch-name> <repository-url>
For example:
$ git clone -b main git@tst.git.net:/path/to/repo.git
Verify Repository Structure
Check for any issues in the repository structure or corruption:
$ git fsck
Resolve any errors found or re-clone the repository from a reliable source.
If you’re working on a shared team, ensure the expected default branch (like main) is clearly communicated or pre-configured by the repository owner.
The admin (if that's you) should always verify that the remote HEAD reference is correctly set to avoid this issue in the future.