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?

  • How smart is git in rebasing in python?
  • working with GIT and multiple projects
  • Git add only all new files, not modified files
  • “The program 'rails' is currently not installed” after git clone
  • MATLAB does not recognize“.m” file changes after switching branches in git
  • how to send somebody my (already generated) github public rsa key(send the key or the .pub file?)
  • 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


    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:

        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?

  • gitlab shows wrong README on project page
  • Is it safe to rename remotes in git?
  • git repository cloning logging
  • Is it possible to use the “minimal” algorithm for interactive adding?
  • git-svn guestion about creating local branches
  • Jenkins Pipeline Submodule Authentication
  • 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      
    $ git push origin master


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


    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.