3

I'm following the Git Pro book ( http://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server ) to set up my first git remote server on Ubuntu. After I follow this:

$ git remote add origin git@gitserver:/opt/git/inventory.git
$ git push origin Windows

I receive this message:

Counting objects: 33, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (28,28) done.
Writing objects: 100% (33/33), 7.30 KiB | 0 bytes/s, done.
Total 33 (delta 13), reused 0 (delta 0)
To git@gitserver:/opt/git/inventory.git
 * [new branch]    Windows -> Windows

But when I type git statuson the remote server (in /opt/git/inventory.git/) I get the error message fatal: This operation must be run in a work tree

The remote repository appears to not contain any of the files from the local repository and when I clone the remote repository into a different local folder there are no files, just the .git folder.

I have looked at other related questions on here:

fatal: This operation must be run in a work tree

Why am I getting the message, "fatal: This operation must be run in a work tree?"

Getting “fatal: This operation must be run in a work tree?” on bare repository

but am no clearer as to why this is happening and what i can do to remedy it.

bordeltabernacle
  • 1,603
  • 5
  • 24
  • 46
  • Read up on `bare` repositories. By definition a `bare` repository doesn't have a work tree, speaks no checked out files. This is expected behaviour. – Sascha Wolf Feb 09 '15 at 14:40

1 Answers1

6

The remote repository in question is a bare repository.

It will only contain the packed objects and refs etc that git internally stores and won't have any of the regular code files checked out. As such, there will be no working tree, and hence no working git status.

That said, to check if your changes were pushed, just clone that repo in question to another location, and you will find your files all right:

git clone /opt/git/inventory.git some/location/inventory_clone

You might need to do a git checkout master in the newly cloned repo to actually see the code files.

Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • when I clone the repository I get the following: `warning: remote HEAD refers to nonexistent ref, unable to checkout.` and there are no files in the cloned repository? – bordeltabernacle Feb 09 '15 at 14:44
  • 1
    @RMPhoenix After you clone the repo, do a `git checkout master`. Check [this](http://stackoverflow.com/a/15631690/1860929) – Anshul Goyal Feb 09 '15 at 14:47
  • 1
    Aha! OK, thankyou, I've got it. I pushed my local repo to my remote server, pulled it back down into a different local folder `inventory_clone` which created another folder `inventory', in that folder I did `git branch -a` to see what branches there were and then `git checkout` on the branch i wanted and there the files were. Thankyou very much @mu I shall read deeper into Git, I think I need to better understand what it is fundamentally doing here. – bordeltabernacle Feb 09 '15 at 15:10
  • Thankyou very much! – Lucas Martins Jun 06 '18 at 22:06