views:

65

answers:

2

This is probably quite a newb question, but I can't seem to figure it out.

Here's what I did...

On the server (via ssh):

  • Created a site on a dedicated server
  • Created a git repo there (git init I think?)
  • Added and committed everything

At my office:

  • Cloned the repo on my development machine
  • Pulled everything
  • Made some changes to local files
  • Added the files again (is this right? not like svn!)
  • Did a commit
  • Did a push

...now, on the server, if I do git show, it shows a diff where the server's last copy of stuff is removed and the stuff I pushed from my office is being added. That's what I want to happen. What I can't figure out is: what do I need to do on the server to make the changes I pushed from my office become "live?"

I've had pretty good success deploying websites with svn in the past, and I figure I can get away with it with git too... but obviously I'm missing some piece of the puzzle. Thanks for any help.


edit - I just noticed this post: http://stackoverflow.com/questions/286988/git-pulling-changes-from-clone-back-onto-the-master

Should I be pulling my office repo onto my server instead of pusing it there? So ssh from the office into the server and then have it git+ssh back into the office to pull that repo? That seems kind of crazy, I'd rather figure out how to make the push go through if possible.


rephrasing the question

I really just want to apply the patch shown by git show. Does git have a built-in way of doing that?


answer

It looks like git checkout -f on the server did what I wanted, but creating a --bare repo would have been a better way to go (I've changed to this setup now).

+1  A: 

If the git repo on the server you pushed to is for the live system, you would probably have to do a [EDIT] git reset [--hard|...] HEAD on the server after a push I guess (see git-reset man page for details on whether using --hard or something else; --hard resets all non-committed modifications on your server).

If the live system is somewhere else on the server, do a git pull from your repo you pushed to (in the directory with your live system).

push and fetch are complementary, i.e. pushing from A to B is like fetching A from B.
pull is a fetch followed by a checkout.

EDIT:
You should also read the article linked to by jmohr on the subtle differences between push and fetch / pull: git push not send changes to remote git repository

Archimedix
`git checkout (something)` or just `git checkout`? `git checkout` shows M (modified?) and a bunch of files, but the changes don't appear and `git show` gives the same output afterwards... weird. +1 for "push and fetch are complementary."
no
`git checkout -f` ("proceed even if the index or working tree is not HEAD") made the changes to the live files, but `git info` still shows the same diff... this bothers me. Should I do a `git clean` or something?
no
Sorry, just updated my answer. It should be `git reset`, but still, pushing to a non-bare repository is not very good practice as it seems. Better have a bare repo and pull from there to your live system.
Archimedix
The git-reset didn't seem to do anything useful as far as cleaning up `git show`, but I probably should have done it before I tried `git checkout -f`... hmm, I'll see what I can do about a bare repo
no
Doing a `git reset --hard HEAD` in the (non-bare) repository you pushed to should update your working copy files to the most recent pushed commit.
Archimedix
It may have done that if I hadn't already done `git checkout -f`, which did do that. The problem I have now is `git show` still shows a diff with those changes when it should probably not. I'll update my question.
no
Running `git show` in your working copy just displays your last commit. The changes have been applied already.
Archimedix
Heheh, yeah I was just realizing that. I marked @dgnorton's answer as correct; I guess --bare was the way to go, but `git checkout -f` and a non-bare repo probably would have worked. Best to do things the Right Way(TM), though.
no
+4  A: 

Usually on the server you would do a git init --bare which creates a repo with no working directory. If that is the route you took then you would have to pull the changes from there to the web directory as the "deployment" step. So your work flow might look like...

On dev PC:

1. git clone <path to server repo>

*make code changes*

2. git commit -am "fixed a bug"

*add some new feature*

3. git commit -am "added cool new feature"

4. git push origin master


On the server:

*cd to www folder*

5. git pull
  1. Clones server repo to your dev machine, which you've already done
  2. Commits the bug fix to your local repo...not the server's repo
  3. Commits the new feature to your local repo...again, not the server's
  4. Pushes all changes from your master branch to the server's master branch

At this point, none of your changes are visible on your website. You would need to "deploy" them.

5.Pulls the latest changes from the central repo on the server to the web server's folder(s) that are being served up on the web.

There git tutorials are very good as is "Pro Git", a free online book

dgnorton
Okay, I'll try this... what steps should I take to set up my 'bare' repo and check everything into it given the position I'm in now? I don't really care about these recent changes, they are small and I can always patch them in later.
no
http://progit.org/book/ch4-4.html ... search for "git --bare init". The stuff above that is for user setup which I presume you've already done.
dgnorton
I'm committing my clone into a bare repo on the server now. Did a `git remote origin (bare repo)`. Should I be able to (re)move the .git folder on the original non-bare repo, then give it a remote to the new (bare, but with my stuff checked in from clone) repo, and then update to sync everything?
no
@no, never tried that before.
dgnorton
Heh, look at this: `git checkout`warning: You appear to be on a branch yet to be born.warning: Forcing checkout of HEAD.fatal: just how do you expect me to merge 0 trees?
no
@no, irc://irc.freenode.net/git ... the git IRC channel is a great resource for live troubleshooting help.
dgnorton
Thanks, got it worked out after a bit of file shuffling.
no