2

Anyone know how to link a local Github repo with the Wamp server? I'm trying to run my project with localhost so I'm using Wamp. Whenever I run these commands

cd C:\Users\my\Documents\GitHub\repo

git --work-tree=C:\wamp\www status

(repo is the name of the repo)

to link them up though (as suggested by another user in this thread Can I combine my local Github repository with WAMP localhost folder?), I get a "fatal: This operation must be run in a work tree."
The user's other answers don't work either.

There have been similar questions on Stack Overflow and I've tried all the suggested solutions, and none have worked. Some suggested that my repository was bare, but I'm able to do git add, commit, push, pull, so I'm not sure why I'm getting that error. I even tried configuring core.bare to false, but still get the same error.

Maybe I don't have enough knowledge in using Github to know why I'm getting this error, but I'd appreciate any help.

Community
  • 1
  • 1
user3226932
  • 2,042
  • 6
  • 39
  • 76
  • Does `git status` work? (when executed in `C:\Users\my\Documents\GitHub\repo`) – VonC Feb 07 '15 at 20:12
  • Just to be sure, can you test a `git --work-tree=C:\wamp\www --git-dir=C:\Users\my\Documents\GitHub\repo status`? – VonC Feb 07 '15 at 20:16
  • Hi VonC, thanks for replying. Git status works. The other command is saying that my repository is not a repository ("fatal: not a git repository") – user3226932 Feb 07 '15 at 20:54

1 Answers1

1

Considering that git --work-tree=C:\wamp\www --git-dir=C:\Users\my\Documents\GitHub\repo status returns:

fatal: not a git repository

That means C:\Users\my\Documents\GitHub\repo is not a valid git repo (maybe no .git folder in it or its path isn't properly recognized in the current shell session)

Note: depending on your current shell, you might need to use posix paths.
In a git bash shell session (as opposed to a git-cmd.bat DOS shell session):

 git --work-tree=/C/wamp/www --git-dir=/c/Users/my/Documents/GitHub/repo status

Since the errors were persistent, the OP concluded:

ended up just git cloning into the www directory and it works now.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • There is a .git folder in it. What does it mean when it's not a valid git repo if I'm able to do the git commands in it. How can I make it a valid git repo? – user3226932 Feb 07 '15 at 21:48
  • @user3226932 none of the answers of http://stackoverflow.com/q/18947567/6309 apply here? – VonC Feb 07 '15 at 21:59
  • @user3226932 does a `git --git-dir=C:\Users\my\Documents\GitHub\repo remote -v` returns an `origin` remote with a `github.com` url? – VonC Feb 07 '15 at 22:06
  • Tried all of the suggested solutions, including re-cloning the repo, but none worked. I still get "fatal: not a git repository" or "fatal: this operation must be run in a work tree". Your more recent comment with the remote -v returned "fatal: Not a git repository: C:UsersmydocumentsgitHubrepo" not sure why the slashes are gone (i replaced my directory names with my and repo for this comment). I am doing all of this inside my repo directory – user3226932 Feb 07 '15 at 22:14
  • @user3226932 are you in a git bash session or in a git-cmd (DOS) session? – VonC Feb 07 '15 at 22:15
  • @user3226932 then I have edited the answer to illustrate posix path – VonC Feb 07 '15 at 22:16
  • tried it with /c/ too but no luck, still "fatal: not a git repository". – user3226932 Feb 07 '15 at 22:20
  • Hi @VonC, I tried this again: git --work-tree=/C/wamp/www status and now it doesn't give me "fatal: This operation must be run in a work tree." for some reason though, now it outputs deleted files (all from my repo) and then shows what's inside the www directory (untracked files). Is this supposed to be happening? Are all the files from repo supposed to be copied to the www directory and not deleted? – user3226932 Feb 07 '15 at 22:39
  • @user3226932 yes, using a custom work tree help Git compare its content with the index of the git repo. If the index references files which are not present in the working tree... they would be displayed as "deleted" (in the working tree) – VonC Feb 08 '15 at 08:22
  • Can you suggest a solution to this? I still have the same issues. – user3226932 Feb 08 '15 at 11:49
  • Could you try the same, this time with a git-cmd.bat. That is with a dos session instead of a bash session. – VonC Feb 08 '15 at 12:24
  • Got the same output (list of deleted files when i do git --work-tree=C:\wamp\www status and not a git repository when i do git --work-tree=C:\wamp\www --git-dir=C:\Users\my\Documents\GitHub\repo status ) – user3226932 Feb 08 '15 at 21:58
  • That seems normal: the point is you haven't an error message anymore. If you want the same content in www as the one in the repo, you can do a checkout (with the samo git-dir and work-tree options) – VonC Feb 09 '15 at 05:02
  • I see. Would git checkout would make a copy of my git repository into the www directory, and that whatever changes I make in my repo directory would automatically update the files in the www directory? What exact commands would I use? Am I trying to make a separate branch? I tried git checkout -b --work-tree=C:\wamp\www --git-dir=C:\Users\my\Documents\GitHub\repo status, but I'm getting invalid branch name and unknown option errors. Thanks for all your help so far btw. I feel like I'm getting closer. – user3226932 Feb 09 '15 at 07:03
  • No, the command would be (abbreviated, because I am typing from a phonein a train) git --work-tree... --git-dir... checkout -- . (Note the final '-- .') – VonC Feb 09 '15 at 07:06
  • aarghh it's still giving me the fatal: not a git repository error, even tho there's a .git directory and i'm inside the git repository directory and i'm able to do other git commands.. – user3226932 Feb 09 '15 at 07:37
  • The full command (since I am no longer in a train) was: ` git --work-tree=C:\wamp\www --git-dir=C:\Users\my\Documents\GitHub\repo checkout -- .` – VonC Feb 09 '15 at 10:00
  • Yes, that's exactly what i tried. should i be doing inside the repo directory? because that's where i'm doing the command from. it's saying repo isn't a git repository for some reason... – user3226932 Feb 09 '15 at 18:36
  • @user3226932 if `C:\Users\my\Documents\GitHub\repo` is a repo, then `--git-dir` option should allow the command to proceed. – VonC Feb 09 '15 at 19:03
  • ended up just git cloning into the www directory and it works now. thanks VonC! – user3226932 Feb 12 '15 at 04:00
  • @user3226932 great! I have included your conclusion in the answer for more visibility. – VonC Feb 12 '15 at 06:58