I'm trying to git clone
a project onto my server. Yet I get a permission denied error.
If I create a new folder with chmod 777
permissions, it works.
What permission level should a folder have to use git clone
into it?
I'm trying to git clone
a project onto my server. Yet I get a permission denied error.
If I create a new folder with chmod 777
permissions, it works.
What permission level should a folder have to use git clone
into it?
The git clone
command, used as:
git clone <url> <destination>
or:
git clone <url>
is shorthand for:
Make a new, empty directory (empty folder) as specified by the destination
argument, or, if it's omitted, as specified by reading the supplied URL and turning that into a best-guess name (the guess is usually fine). There's one exception to this rule and that is if the destination
argument is already a directory (folder), it must be empty, and then git clone
uses it, rather than making it.
In that new directory (folder), create a new empty repository with git init
. This creates a sub-directory (sub-folder) named .git
and populates it with files.
In that same directory, run git remote add
: this updates the .git/config
file created in step 2. This command needs at least two arguments; one of them is supplied by the url
you gave, and the other defaults to the name origin
(but you can add options to git clone
to use some other name, if you want). This name is the name of a remote. There's no reason to use anything other than origin
here, and below, I'll assume you didn't change this.
Again in that same directory, run any additional git config
commands required (as specified by options).
Again in that same directory, run git fetch origin
. This populates the empty Git repository created in step 2 with commits and other internal Git objects. There are, as yet, no files in the main directory (only in the hidden .git
sub-directory). It also reads out the other Git repository's branch names, and uses those to make remote-tracking names (not branch names!) in your new repository. You thus have all the commits, but no branches.
Finally, run git checkout
or git switch
in that same directory, to extract some particular commit, as found by some particular remote-tracking name, creating, in the process, one branch name in your own new repository. This last step will create files and sub-directories within the directory created in step 1.
This means that the permissions required are:
destination
argument (possibly implied);On a Unix-like system, this requires rwx
permission for you, the user (mode 0700
at a minimum) on the destination path. The typical setting on most systems is 0755
(rwxr-xr-x
) or 0750
(rwxr-x---
). Git will, internally, ask for mode 0777
(rwxrwxrwx
) on directories and 0666
(rw-rw-rw-
) on files, but your umask setting—which is pretty typically 022
—will take away write permission for group and/or other, and possibly more permissions. For instance, a umask setting of 077
takes away ---rwxrwx
so that a request to create as rw-rw-rw-
winds up creating as rw-------
. Note how the bits that are set in the "umask" wind up cleared (not-set) in the final file or directory.
Non-Unix-like systems, e.g., those with ACLs, are often much more complicated and generally require a much more complicated setup to administer.