Reputation: 65
I have a remote repository that is kept on my ubuntu server
I ran git init --bare
in /home/USER/git/project.git/ and I have that set to my remote url that I push to from my local machine. /home/USER/git/project.git
points to /var/www/project/
because of a file I have /home/USER/git/project.git/hooks/post-receive
post-receive contents:
#!/bin/sh
GIT_WORK_TREE=/var/www/project git checkout -f
I can push changes I have made to my master branch and they will show up in /var/www/project/
but if I make a new branch it doesn't exist in this directory. But I can see it in /home/USER/git/project.git
. Why doesn't the branch make it to the folder I've pointed my checkouts to?
Thank you
Upvotes: 0
Views: 85
Reputation: 45659
Commits you push to refs other than master
don't make it to your working directory because your hook doesn't tell git to put them there.
Your bare repo's HEAD
is at master
; so git checkout -f
updates the working tree from master
, regardless of what you just pushed.
I guess you could write a more sophisticated hook, that checks which ref(s) were updated by a push, and behaves accordingly; but there's a problem as you might note from the phrasing ("ref(s)"). What will you do if multiple refs were updated? Which one will you check out?
If you choose to do this sort of git-based deployment, the normal behavior is that a branch corresponds to a working tree, and often that means master
corresponds to the one working tree.
(For the record, I'm not a fan of this sort of git-based deployment, because inevitably needs grow beyond what can be done conveniently, and people start stretching to make git try to do things that a real deployment tool would do. Arguably wanting multiple branches to deploy to the same working tree is already an example of that.)
Upvotes: 1