1

I'm attempting to configure Git for web deployment purposes, according to the directions provided here. However, I can only get as far as step two before things start to go awry.

Now the instructions say to input the following:

git remote add myServer myUsername@ServerHostname:~/path/to/myRepo.git

So I go ahead and plug in

git remote add xxxyyy user@XXX.XXX.XX.XXX:/var/myRepo.git

because I've created the repo--as instructed--outside my web directory. However, doing so gets me the following:

fatal: Not a git repository (or any of the parent directories): .git

So I'm not sure if I'm misinterpreting something in the command syntax or what, but I'm quite confused. As far as specifics are concerned, the environment I'm looking to deploy to is a VPS I've setup with Digital Ocean, and the environment I'm looking to develop in and deploy from is a Xubuntu virtualbox.

EDIT: Problem has been solved with VonC's most gracious assistance. Thanks to everyone who contributed!

user968270
  • 2,551
  • 5
  • 19
  • 19

1 Answers1

2

You need to be in your local repo (the one you want to be deployed) in order to make that command.

 cd /path/tpo/your/local/repo
 git remote add xxxyyy user@XXX.XXX.XX.XXX:/var/myRepo.git

Then you will be able to push (and populate) the bare repo on the server with:

 git push -u myServer master

(sill executed from your local repo folder)

Note the -u: I like to establish a remote tracking branch relationship between your local master and your server repo master, especially when the remote repo is empty.
See "Why do I need to explicitly push a new branch?"
After that, a simple git push will be enough.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Ah, okay. The instructions don't appear to make any mention of having a local repo already in place. So, am I just going to create a bare repository in the directory where my website's files live? – user968270 Jan 04 '14 at 09:44
  • @user968270 no, you need a non-bare one locally, that is one with a working tree. A bare one is for the server, for you to push to (bare menaning no working tree, meaning no risk to discrepancy between a remote working tree and the branch you are pushing): http://bitflop.com/document/111 – VonC Jan 04 '14 at 10:42
  • @user968270 see more for what is a bare repo at http://htmlpreview.github.io/?https://github.com/sitaramc/sitaramc.github.com/blob/dce410b2a2804723676db9cabd7bb506b6d9ba05/concepts/bare-all.html. – VonC Jan 04 '14 at 10:48
  • I initialized a Git repository locally inside my web directory and applied the 'remote add' command that makes up the first part of the second step in the instructions. I didn't bother to run the push command, as the repository is empty at the moment, moved on to step three, cloning the repository as instructed, which went off without a hitch. However, when I move on to the fourth step and enter 'env -i git pull --ff-only origin master' I get the error 'fatal: Couldn't find remote ref master.' – user968270 Jan 06 '14 at 12:02
  • @user968270 normal: master is only created when there is at least one commit. No commit, no branch (master or otherwise) – VonC Jan 06 '14 at 12:07
  • Gah, sorry, this is all new to me, and I'm clearly missing something in the instructions I linked. At this point, I have the bare repository on my server outside the web directory. I have a non-bare repository on the local machine in which I ran the 'remote add' command, and I cloned the repo into the web directory on the server--an instruction which I'm not clear on the purpose of at all--but that still leaves me with none of the files I want to track on the local machine. I'm pretty utterly lost here and have the suspicion I should start over. – user968270 Jan 06 '14 at 12:33
  • @user968270 You need to add the bare repo url as a remote to your non-bare repo: then you can push to it. But you will need a post-receive hook on the bare repo in order to checkout its content to your live server folder, as in: http://stackoverflow.com/a/20933039/6309 – VonC Jan 06 '14 at 12:46
  • @user968270 if you don't see it, you can go ahead and just create it (make sure it is executable). – VonC Jan 06 '14 at 13:15
  • At this point, I can push my changes to the server, but it seems like the hook isn't working, because the changes don't get passed to the live (cloned) repository, meaning the website doesn't change accordingly. – user968270 Jan 06 '14 at 14:34
  • @user968270 Sorry, I didn't see your chat immediately. I answered there – VonC Jan 06 '14 at 14:35
  • @user968270 make sure your hook is executable, and add an echo in it to see if at least it is triggered. – VonC Jan 06 '14 at 14:55