Last Updated: February 25, 2016
· helmedeiros

Git Repository - failed to push some refs

Git is a very powerful VCS to maintain our code. We can share and keep history of our code so effectively, but it can be a bit heavy for those who have become accustomed to for a long distance in creating and maintaining version control servers.

Those coming from SVN usually have to constantly remember that now and users are also operational staff, and your git repository is actually a server and also a potential sharing source.

To serve others directly from your machine git give as a repository called bare, as you wish you can share a old or a new repository, for that you should:

Existent project:

$ git clone --bare --shared <your local or remote repository url>

New project:

$ git init --bare --shared=group


After do that anyone is able to get your ip and connect directly to your repository using for example ssh protocolo, like:

$ git clone <ssh user_name>@<repository machine ip>:<repository address>.git

After you add some stuff... commit them and after all finished push it! BANG!! Start all problems...
As you should notice there are some differences in the way both new and existent projects were defined. If some other person tries to add/commit/push same files, or content (git keep both as same objects), we will face the following error:

$ git push
Counting objects: 31, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (17/17), done.
Writing objects: 100% (21/21), 2.07 KiB | 0 bytes/s, done.
Total 21 (delta 12), reused 0 (delta 0)
remote: error: insufficient permission for adding an object to repository database ./objects  remote: fatal: failed to write object

To solve this problem you have to have something in mind operational system's permissions system as you are restricted by it in this case. Tu understand better the problem, go ahead and check your git object's folder (.git/objects). You will probably see something like that:

<your user_name>@<the machine name> objects]$ ls -la
total 200
drwxr-xr-x 25 <your user_name> <group_name> 2048 Feb 10 09:28 .
drwxr-xr-x  3 <his user_name> <group_name> 1024 Feb  3 15:06 ..
drwxr-xr-x  2 <his user_name> <group_name> 1024 Jan 31 13:39 02
drwxr-xr-x  2 <his user_name> <group_name> 1024 Feb  3 13:24 08

*Note that those file's permissions were granted only for your users, no one will never can changed it... *

          Nível  u   g   o
Permissão rwx r-x ---
     Binário 111 101 000
          Octal  7   5   0


If you have super user permission, you can go forward and change all permissions by yourself using the step two, in any-other case you will need to ask all users with objects created with their users, use the following command to know who they are:

$ ls -la | awk '{print $3}' | sort -u 
<your user_name>
<his user_name>

Now you and all file's owner users will have to change those files permission, doing:

$ chmod -R 774 .

After that you will need to add a new property that is equivalent to --shared=group done for the new repository, according to the documentation, this make the repository group-writable, do it executing:

$ git config core.sharedRepository group