Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push to remote server and Github

Tags:

git

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.

like image 313
Daniel Avatar asked Oct 08 '22 15:10

Daniel


1 Answers

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)

like image 78
VonC Avatar answered Oct 12 '22 11:10

VonC