gitlab unable to push to remote - mungitoperrito/various GitHub Wiki

Problem: Unable to push to remote repo

Context and Symptoms: Running git fsck on the remote server produces a seg fault. Operations using the local git client produce errors like these:

remote: error: object file /data/git-data/repositories/group/projectname.git/objects/b6/cf1d68fc7e482bdbdaf04bb69a0074adc0781e is empty
remote: fatal: loose object b6cf1d68fc7e482bdbdaf04bb69a0074adc0781e (stored in /data/git-data/repositories/group/projectname.git/objects/b6/cf1d68fc7e482bdbdaf04bb69a0074adc0781e) is corrupt
error: object file /data/git-data/repositories/group/projectname.git/objects/b6/cf1d68fc7e482bdbdaf04bb69a0074adc0781e is empty
fatal: loose object b6cf1d68fc7e482bdbdaf04bb69a0074adc0781e (stored in /data/git-data/repositories/group/projectname.git/objects/b6/cf1d68fc7e482bdbdaf04bb69a0074adc0781e) is corrupt
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To git.gitlabhost.com:group/projectname.git
 ! [remote rejected]   master -> master (missing necessary objects) 

Solution

Find the 0 size commit objects on the remote server and replace them with good copies from a local repo

cd /data/git-data/repositories/group/projectname.git/objects
find . -size 0 -print

For each size 0 file listed, copy over the corresponding object file from the local repo to the gitlab server

cp .git/objects/b6/cf1d68fc7e482bdbdaf04bb69a0074adc0781e /u1/shared   # From local repo to a shared drive
cd /data/git-data/repositories/group/projectname.git/objects           # On remote server
cp /u1/shared/cf1d68fc7e482bdbdaf04bb69a0074adc0781e b6                # From shared drive to gitlab repo

Once the repo is repaired check the log directory to be sure permissions are correct.

ls -l /data/git-data/repositories/group/projectname.git

The permissions should all be git.root. If they are not correct fix them using chmod

chmod -R git.root logs