git push error, unable to write sha1 filename ./objects - linux

Here is a problem.
I create a new repository with
mkdir -p repositories/project.git
cd repositories/project.git
git init --bare --shared=all
The repository is at shared local folder. UMASK is 022.
Later on, folks in my team are able to clone the project and push a few changes.
However, soon they come across this issue when they try to do 'git push'.
error: unable to write sha1 filename ./objects/3c/c2f933427a4215d3237a0c3b874a4ff16725: Permission denied
To myaccountname#nameofthecomputer:/repositories/project.git
! [remote rejected] master -> master (unable to migrate objects to permanent storage)
error: failed to push some refs to 'myaccountname#nameofthecomputer:/repositories/project.git'
The problem is obviously in the way git creates some internal files/objects, because if I do:
sudo chmod -R 777 project.git
the problem is temporarily gone.
What am I doing wrong?

git init --shared=all makes the repository readable by all users, but not writable by all users. Making any directory writable by all users (without using the sticky bit) is generally a colossal security risk, so Git doesn't provide that as an option.
If you want people to all be able to write to a Git repository this way, then places them all in a single group, say git. Change the main repository and all of its subdirectories to have that group, and make each directory setgid. That means that each directory and file that's created will have the group git. Since with --shared=all, Git will make all files and directories writable by that group, users should be able to push normally to the repository.
Note that the umask is not relevant here, since Git will adjust the permissions to honor the setting you specified.

Related

How can I correctly create a centralized Git repository on a Linux Server? Why I have this error following this tutorial?

I am pretty new in Git and I am installing a centralized GIT repository on a Linux server following this tutorial: http://toroid.org/git-central-repo-howto
It show these 2 first steps:
$ git init --bare --shared foo.git
Initialized empty shared Git repository in /git/foo.git/
$ chgrp -R dev foo.git
So basically the first command:
git init --bare --shared foo.git
I think that it means that I am creating a new empty foo repository (is foo the name of the created repository?).
From what I have understand the --bare option means that this repository is not associated to a working tree. Why?
Reading this documentation: https://git-scm.com/docs/git-init I can understand that --shared means that this repository is to be shared amongst several users. This allows users belonging to the same group to push into that repository.
But what users? Users of what?
The second statement is:
chgrp -R dev foo.git
From what I have understand it set the foo.git directory (my repository) and all its content to the dev group.
The problem is performing this command I obtain this error message in my shell:
XXX#YYY:~$ chgrp -R dev foo.git
chgrp: invalid group: ‘dev’
I am not so into Linux but I think that it means that the dev group doesn't exit on my server. Why have I to associate this repository folder (and its content) to a group? How can I solve this issue?
Re-read manual:
The easy way to give people read-write access to it (repository) is to
add all the relevant users to one group (say dev), and give that group
ownership of the repository
and
The --shared option sets the permissions on everything in the
repository to group-writable.
ssh:// access-type to repo assumed. I.e. user belongs to local group, all members of which have RW rigths in the repository on FS-level
I'm quite new to GIT myself, but I think you just need to create linux group "dev" beforehand, or use an already existing group. You can add users of the linux server into that group. The users of the group could later clone/pull from/push to your repository.
Link about managing groups:
https://wiki.archlinux.org/index.php/users_and_groups

Redmine error log fatal:not a git repository

I installed redmine on git server (gitlab), which is our main git server (same machine).
When I add the repository (through gitlab) information in redmine web,
The redmine log says:
/usr/local/redmine/log/production.scm.stderr.log <
fatal: Not a git repository: '/data/gitlab/git-data/repositories/woojs/RedmineTestProject.git/'
But when I check the whether bare or non-bare using git command, I get this:
root#gitserver:/data/gitlab/git-data/repositories/woojs/RedmineTestProject.git# git rev-parse --is-bare-repository
true
I tried to change some things related to permissions: Changing owner to www-data and changing permissions to 777. It's still not working.
Similar to this old thread, check the account which runs for redmine: does that account has the right to access /data/gitlab/git-data/repositories/woojs/RedmineTestProject.git? (or anything under /data/gitlab/git-data/repositories/?)
This usually is a right access issue.

How to fix permission denied for .git/ directory when performing git push?

I have set up a git repository on my server. Created a new user 'git'. My repos are located in /srv/git/example.git. I was able to git remote add origin git#domain/srv/git/example.git then I added and committed my changes.
However when I tried git push origin master it failed on:
fatal: unable to create temporary file: permission denied' and 'fatal: sha1 file write error: invalid argument'
On the server I ran:
sudo chown -R git:git /srv/git/`
This fixed my problem but I am wondering if this was the correct thing to do?
On the server I ran sudo chown -R git:git /srv/git/ - this fixed my problem but I am wondering if this was the correct thing to do?
Absolutely. The problem previously was that the git user, who you're logging in as via SSH, could not write to the repository.
Depending on your needs, you may consider different combinations of users and SSH keys, or one of the many additional programs (gitolite etc) that can be used to more finely control access.
First, fix file permissions in your remote .git dir e.g.
sudo chmod -R ug+w /var/www/.git
sudo chown -R git:git /var/www/.git
or root:root if you want to assign members of root group for push access.
Then git repository on the destination host needs to be set as shared, so the following command on remote needs to be run:
git config core.sharedRepository group

Deploy with git pull on webserver on /var/www/vhosts

Can I create with git files owned by root without using root to push?
I use git user to push on the webserver. But /var/www is owned by root or www-data with no write access for other user.
I can pull in an other directory and use "hook/post-receive" but still this hook is executed with the git user...
For the moment I log in the webserver and do a sudo git pull origin. But it will be more efficient if I was hable to do a git pull server from my laptop.
Thanks
Just putting my comment here as answer, since as far as I know, it will completely fix the problem:
Make a symlink in /var/www to a map owned by the git user (e.g. /home/git/www). Then push your files to this /home/git/www map. No problems with permissions anymore.
My solution was to give all files to git by way of the www-pub group with read permission for everyone—except settings files with the MySQL password.
I push to /home/git/repository/project and checkout to /var/www/project using hook/post-receive.

git: can't push (unpacker error) related to permission issues

I have this problem when i try to push in git:
error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To ssh://<repo url>/<repo dir>
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'ssh://<repo url>/<repo dir>'
I've had this before sporadically and we've always had to solve it by each user sshing to the repo and setting group permissions on all the files therein with
chmod -R g+w *
This was never a satisfactory solution and now it's bitten us in the arse as one of the guys is away and no-one knows his repo user's password. So, i'm trying to solve it properly.
The error seems to occur when someone tries to push up a change that will alter a repo dir that is owned by another user (hence setting the group write option above). I've done a bit of googling around this and have found a couple of solutions being discussed (neither of which worked for me)
1) make sure that the group that the repo dirs are shared with is each users' primary group (i believe that is the case already: each user has only one group so that must be their primary group, right?)
2) git repo core.sharedRepository setting, as detailed here: Git: Can't push from one computer
I changed this but it didn't make any difference. Do i need to reload the config or something to actually effect the change?
Here's what my repo config looks like atm:
[core]
repositoryformatversion = 0
filemode = true
bare = true
sharedRepository = all
[receive]
denyNonFastForwards = True
Grateful for any advice or suggestions!
max
I had this error for two weeks, and the majority of the solutions stated 'chmod -R' as the the answer, unfortunately for me my git repos (local / remote / shared - with team) were all on Windows OS, and even though chmod -Rv showed all the files changed to 'rwxrwxrwx', a subsequent 'ls -l' still showed all files as 'rwxr-xr-x' and the error repeated itself. I eventually saw this solution by Ariejan de Vroom. It worked and we were all able to pull and push again.
On both local (the local that is having trouble pushing) and remote repos, run the following commands:
$ git fsck
$ git prune
$ git repack
$ git fsck
On a side note, I tried using Windows' native file permissions / ACL and even resorted to elevating the problem user to Administrator, but none of that seemed to help. Not sure if the environment is important, but it may help someone with a similar setup - problem team member and remote (Windows Server 2008 R2 Standard), my local (Windows 7 VM).
A simpler way to do this is to add a post-receive script which runs the chmod command
after every push to the 'hub' repo on the server. Add the following line to hooks/post-receive inside your git folder on the server:
chmod -Rf u+w /path/to/git/repo/objects
It is a permission error. The way that was most appropriate and secure for me was adding users to a supplementary group that the repo. is owned by (or vice versa):
groupadd git
chgrp -R git .git
chgrp -R git ./
usermod -G -a git $(whoami)
In case anyone else is stuck with this: it just means the write
permissions are wrong in the repo that you’re pushing to. Go and chmod
-R it so that the user you’re accessing the git server with has write access.
For me, this error occurred when I was out of space on my remote.
I just needed to read the rest of the error message:
error: file write error (No space left on device)
fatal: unable to write sha1 file
error: unpack failed: unpack-objects abnormal exit
For the permission error using git repository on AWS instance, I successfully solved it by creating a group, and assigning it to the repository folder recursively(-R), and give the written right to this group, and then assign the default aws instance user(ec2-user or ubuntu) to this group.
1. Create a goup name share_group or something else
sudo groupadd share_group
2. change the repository folder from 'root' group to 'share_group'
sudo chgrp -R share_group /path/to/your/repository
3. add the write authority to share_group
sudo chmod -R g+w /path/to/your/repository
4. The last step is to assign current user--default user when login (by default ec2 is 'ec2-user', user of ubuntu instance is 'ubuntu' in ubuntu on aws) to share_group. I am using ubuntu insance on aws, so my default user is ubuntu.
sudo usermod -a -G share_group ubuntu
By the way, to see the ownership of the folder or file just type:
ls -l /path/to/your/repository
'
Output:
drwxr-x--x 2 root shared_group
(explanation please see:https://wiki.archlinux.org/index.php/File_permissions_and_attributes).
After step 3, you will see
drwx--x--x 2 root root
changed to
drwxr-x--x 2 root share_group
In this case, I did not assign user 'ubuntu' to root group, for the consideration of security. You can just try to assign you default user to root according to step 4 (just skip the first 3 steps
In another way, tried the solution by :
chmod -Rf u+w /path/to/git/repo/objects
It did not work for me, I think it should be the reason that my repository folder belong to the root user, not to Ubuntu user, and 'git' by default use the default user(ec2-user or Ubuntu user. You can try to change the user and test it.
Finally, below code definitely work for me, but 777 is not good for security
sudo chmod -R 777 /path/to/your/repo
I use gitosis for managing this kind of stuff. Gitosis has a single user (usually called "git") that owns all the repositories, and it uses public-key-based access control to each repo. It might not suit your setup but is probably worth checking out (no pun intended).
This problem can also occur after Ubuntu upgrades that require a reboot.
If the file /var/run/reboot-required exists, do or schedule a restart.
I was getting similar error and please see below how I resolved it.
My directory structure:
/opt/git/project.git
and git user is git
$ cd /opt/git/project.git
$ sudo chown -R git:git .
chown with -R option recursively changes the ownership and and group (since i typed git:git in above command) of the current directory. chown -R is necessary since git changes many files inside your git directory when you push to the repository.
I was having trouble with this too, thinking my remote gitolite-admin was corrupted or something wrong.
My setup is Mac OS X (10.6.6) laptop with remote Ubuntu 10 server with gitolite.
It turned out that the problem was with my local checkout of gitolite-admin.
Despite the "unpack failed" error, it turned out the the problem was local.
I figured this out by checking it out again as gitolite-admin2, making a change, and the pushing.
Voila! It worked!
For what it worth, I had the same problem over my own VPS and it was caused by my low hard disk space on VPS. Confirmed by df -h command and after i cleaned up my VPS' hard disk; the problem was gone.
Cheers.
Where I work we have been using this method on all of our repositories for a few years without any problems (except when we create a new repository and forget to set it up this way):
Set 'sharedRepository = true' in the config file's '[core]' section.
Change the group id of the repository to a group shared by all users who are allowed to push to it:
chgrp -R shared_group /git/our_repos
chmod -R g+w /git/our_repos
Set the setgid bit on all directories in the repository so that new files/directories keep the same group:
find /git/our_repos -type d -exec chmod g+s {} +
Add this line to the pre-receive hook in the repository to ensure new file permissions allow group read/write:
umask 007
For me its a permissions issue:
On the git server run this command on the repo directory
sudo chmod -R 777 theDirectory/
A git configuration mistake can also product this error. I give my students and example of configuration like this:
git config --global user.name "John Doe"
git config --global user.email johndoe#example.com
One of my students was getting the unpacker error. Other students were fine, but I still did a double check on the git server's permissions and to be sure the student was in proper group.
Finally, I had the student do a git log and saw that he had John Doe for his configuration, but his branch was his own name.
Setting up his configuration properly eliminated the error .
I had similar problem like this before:
! [remote rejected] master -> master (unpacker error)
error: failed to push some refs to 'https://mywebsite.com/my-git-directory.git'
In my case, I have checked wrong directory ownership with ls -l. I change the directory owner to www-data to solve the problem like this:
sudo chown -R www-data:www-data my-git-directory.git/
But in this case I not use SSH method, I use HTTP method.
Maybe when we make sure the directory owner is correct, it can solve the problem.

Resources