fatal: Unable to create temporary file '/home/username/git/myrepo.git/./objects/pack/tmp_pack_XXXXXX': Permission denied

I have been having trouble with this error message and I don’t understand the proper solution to fix it or go about debugging it. I have googled the error in various forms but no real solution has presented itself. I am assuming it’s an issue with permissions but I don’t really know how to check or what I should check for.

I have a server running Ubuntu 11.10 and I’m basically trying to make the initial commit to my git repo from my development machine. I’m running as root. Should I be running as the user?

  • Git: How to prevent committing files that were modified just for debugging purposes?
  • Create new git repo from already existing repo's subdirectory
  • Calling git from Java with command line
  • Git remove directory
  • Creating aliases in PowerShell for git commands?
  • Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?
  • Repo creation on server:

    $ cd /home/username/git
    $ mkdir myrepo.git
    $ cd myrepo.git/
    $ git --bare init
    

    Repo creation on development machine:

    Goto rails project directory first
    $ git init
    $ git add .
    $ git commit -m "initial commit"
    $ bundle pack
    $ git add Gemfile.lock vendor/cache
    $ git commit -m "bundle gems"
    $ git remote add origin ssh://username@server.com/home/username/git/myrepo.git
    $ git push origin master
    

    Error:

    fatal: Unable to create temporary file '/home/username/git/myrepo.git/./objects/pack/tmp_pack_XXXXXX': Permission denied
    error: pack-objects died of signal 13
    error: failed to push some refs to 'ssh://username@server.com/home/username/git/myrepo.git'
    

    My .git/config file:

    [core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
    [remote "origin"]
        url = ssh://username@server.com/home/username/git/myrepo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    

    Similar question:
    How do I do an initial push to a remote repository with Git?

  • Git and IntelliJ lines separator issue
  • How to find which git branch I am on when my disk is mounted on other server
  • Link to existing github repository
  • Cannot get my post-commit script to run (git)
  • Trouble merging upstream changes back into my branch
  • Creating satis composer private repository for wordpress themes and plugins
  • 4 Solutions collect form web for “fatal: Unable to create temporary file '/home/username/git/myrepo.git/./objects/pack/tmp_pack_XXXXXX': Permission denied”

    It sounds like you have file in the git repo owned by root. Since you’re ssh’ing in as ‘username’ to do the push, the files must be writable by username. The easiest thing is probably to create the repo as the user, and use the same user to do your pushes. Another option is to create a group, make everything writable by the group, and make your user a member of that group.

    Ok, I figured it out. The issue was that I didn’t have the correct permissions set for myrepo.git and the parent directory git.

    As root I logged into the server and used:

    $ chown username /home/username/git
    

    This then returns drwxrwxr-x 4 username root 4096 2012-10-30 15:51 /home/username/git with the following:

    $ ls -ld /home/username/git
    

    I then make a new directory for myrepo.git inside git:

    $ mkdir myrepo.git
    $ ls -ld myrepo.git/
    drwxr-xr-x 2 root root 4096 2012-10-30 18:41 myrepo.git/
    

    but it has the user set to root, so I change it to username the same way as before.

    $ chown username myrepo.git/
    $ ls -ld myrepo.git/
    drwxr-xr-x 2 username root 4096 2012-10-30 18:41 myrepo.git/
    

    I then sign out of root and sign into server as username:

    Inside git directory:

    $ cd myrepo.git/
    $ git --bare init
    Initialized empty Git repository in /home/username/git/myrepo.git/
    

    On local machine:

    $ git remote add origin      
    ssh://username@server.com/home/username/git/myrepo.git
    $ git push origin master
    

    SUCCESS!

    Hopefully this comes in handy for anyone else that runs into the same issue in the future!

    Resources

    It would seem like your user doesn’t have permission to write to that directory on the server. Please make sure that the permissions are correct. The user will need write permissions on that directory.

    Thanks to Don Branson,I solve my problem.I think next time i should use this code when i build my repo on server:

    root@localhost:~#mkdir foldername
    root@localhost:~#cd foldername
    root@localhost:~#git init --bare
    root@localhost:~#cd ../
    root@localhost:~#chown -R usergroup:username foldername
    

    And on client,i user this

    $ git remote add origin git@servername:/var/git/foldername
    $ git push origin master
    
    Git Baby is a git and github fan, let's start git clone.