views:

138

answers:

4

I think I said that all correctly.

I've got a staging server with Git on it, my buddy and I push changes to that Git repo from our local clones of that repo, when we're ready to make something public, we tag it 'n all that, but then I have to do a git reset --hard to update the actual files on the server to HEAD, which seems a bit strange to me.

I think the issue might be a fundamental misunderstand of how git works. Usually I branch my code on my local repo, work on it, then merge it to the master repo, then git push, is this correct?

Sorry, I'm quite a newbie when it comes to git, any resources for working with remote git repos would be greatly appreciated, thanks!

+1  A: 

An excellent resource is the Pro Git book by Scott Chacon. It can be found online at http://progit.org/book

Gary Swanson
+1  A: 

I don't fully understand your question, but I can recommend you this workflow that was very useful for our team. In this other post you will find scripts to automatize it, but I find that it is best at the beginning to run the full git commands, to interiorize the process.

Also, this resource about hosted repositories and gitosis is very good. This practical links, plus reading a book about git, was very useful for us to be able to adopt quickly git.

nacmartin
I believe that is -just- what I was looking for, thanks!
Zack
+7  A: 

It sounds like you're pushing to a non-bare repo on your server. When you push to a repo, the repo's internal state is changed, but the checked-out files are not updated, which is why you have to do a git reset --hard (or a git checkout) to checkout updated copies of the files. It is recommended to only push to a bare repo for this reason. You can create a bare repo using git --bare init or git clone --bare.

mipadi
This may come out to be something useful, also. Bare repos were something I hadn't really looked into much. This would give me just the "git" portion of the project? I'm guessing I'd keep the bare repo on my staging server and clone it to get the files "out" of it?
Zack
Yeah -- a bare repo contains the information tracked by Git, but without a checked-out copy of the files. Generally speaking, you should place a bare copy on the server and push to that.
mipadi
See 'Why won't I see changes in the remote repo after "git push"?' in Git FAQ page: http://git.wiki.kernel.org/index.php/GitFaq#Why_won.27t_I_see_changes_in_the_remote_repo_after_.22git_push.22.3F
Jakub Narębski
@mipadi it sounds like @Zack is using a non-bare repo to "publish" files e.g. on a web server. So using a bare repository is a good idea, but they'll need to set up gitweb or something
Dominic Cooney
What I'm doing here is setting up Git for my Django projects. What I've done now is made bare repos on the production server in, for example, /var/git/some-project.git/, then cloned them locally on the production server to /var/django-projects/some-project/. When I've got a bug-free release ready to go, I git push the code to the server, then git pull it from the bare repo to the "working" repo on the server.
Zack
+2  A: 

Zack,

I think the problem is that your remote is not a bare repository (i.e., it has a working tree associated with it). You should never push into a non-bare repository, because this updates the index/cache, but not the working tree. The (non-bare) repository working tree only updates correctly when you run "git reset --hard" because this command changes the working tree state to reflect the state of the last commit, i.e., the commit you just pushed.

The remote repository should be created with the "--bare" flag, i.e., you should create the repo by calling:

$ git init --bare

and then you can correcly push your changes into it.

I describe a development workflow using multiple repositories here, while I provide scripts/aliases/tips to in the second part of the article.

Jeet
Thanks for this, it helped me get to my current solution
Zack