5

Summary: I want to edit files locally, then push to both Github and my web server.

I have the two remotes set up without issue, so right now I am sort of able to do this; however, I have to have branch A checked out locally, and branch B on the server. Then I have to SSH into the server and check out branch A (the one I want). I really don't even want or need a second branch, but many posts suggest that you can't or shouldn't push to a non-bare repository. There must be a better way. Even just using rsync would be easier than this (and I did it for a while).

Strangely, this never happens on Github. Almost all my repos only have one branch and I've never gotten this warning.

The warning message says that you can set receive.denyCurrentBranch to ignore, but I don't know how safe/sane it is. I'm hoping someone will understand my vague description (which is due to my limited knowledge of git) and know the optimum solution.

Daniel
  • 960
  • 1
  • 9
  • 14

1 Answers1

4

It would be easier to set-up a post-receive hook on a bare repo on your web server.
That way, this hook can:

  • change directory and pull the new changes to the actual non-bare repo
  • checkout the branch you want

See "Git Post-Receive Hook for Website Staging" and the work in "Using Git to manage a web site":

$ mkdir /var/www/www.example.org
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
$ chmod +x hooks/post-receive

(Note: fun fact, you can push to two different remote repos simultaneously)

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • It took me a minute to digest: `/var/www/www.example.org` is the actual site dir on the server, the `post-receive` file goes in the bare repo on the server (must be a different dir), and the URL to push to is the bare repo. I actually read that guide you mentioned before asking. I got confused when the site.git dir didn't have any of my files, but I think I understand how it works now. Thanks. – Daniel Jun 05 '12 at 22:06