I'm trying to pull from a remote repo I've just set up and I'm getting the message git-pull cannot be used without a working tree
Everything I've read seems to point at my .git directory but it seems fine
git branch
gives the output
* master
and
git ls-tree --full-tree -r HEAD
list loads of entries like this
100644 blob c825c0607f77e1df4e05920037a2ce09c08e5180app/assets/javascripts/ready.js
which looks correct and makes me think I have managed to push the files correctly to this repo ?
git status
give the output
fatal: This operation must be run in a work tree
and ls -l .git gives
drwxrwxr-x 2 roy roy 4096 Feb 6 14:24 branches
-rw-rw-r-- 1 roy roy 66 Feb 6 14:24 config
-rw-rw-r-- 1 roy roy 73 Feb 6 14:24 description
-rw-rw-r-- 1 roy roy 23 Feb 6 14:24 HEAD
drwxrwxr-x 2 roy roy 4096 Feb 6 14:24 hooks
drwxrwxr-x 2 roy roy 4096 Feb 6 14:24 info
drwxrwxr-x 4 roy roy 4096 Feb 6 14:24 objects
drwxrwxr-x 4 roy roy 4096 Feb 6 14:24 refs
which does seem a bit odd, as it looks just like it did before the push.
can anyone help me with what I'm doing wrong? Is there something I have to do before I can do a git pull ? am I confused by that ls-tree command and the files haven't been pushed?
It seems you are working in a bare repository.
A bare repository is just like an ordinary one, except it has no working directory associated.
Being pull
a fetch
plus a merge
, it cannot be applied to bare repositories.
In details:
A git repository, after all, is just a .git
directory with a defined set of metadata stored in special directories (like refs
, where local and remote branches are stored, and objects
, which contains all the file contents, and so on).
Usually, a git repository is associated with a so called Working directory, which is the checkout of a certain commit: the developer can use the Working directory to perform modifications to the source code, and hence prepare the next commit.
Yet, sometimes, there's no need to have a Working directory. The most common case is when a repository is hosted in a shared server and it is used as the central, shared place used by developers to integrate their code. The repository must store all the information (hence, it has its own copy of the .git
directory), and developers can push their contribution to it, but no developers are meant to directly work on it; so, no Working directory is provided. This is a bare repository.
Now, there are some git commands that operate on the Working directory. These commands are not working on a bare repository, since it lacks a Working directory.
git pull
is one of them. git pull
is the combination of git fetch
and git merge
. Now, git fetch
involves only the .git
directory, so it can be performed on a bare repository. On the other side, git merge
requires a merge on the Working Directory to be performed. And since the working directory is not present, the command will fail.
pull
and merge
are not the only commands that cannot be performed on a bare repository. I strongly suggest you yo have a look to this interactive map which will help you to select which operations cannot be performed on a bare repository (see the amazing Interactive Git Cheatsheet)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With