Deploy web site via Git -


i work on team of web developers. each have personal web site set in our home directories on development server.

we want convert them git working repos can branch, rebase, , enjoy benefits of git goodness.

in reading online, there's couple of options:

1) create bare repo syncs working repo in www/ via post-receive hook

2) push directly working repo

problem option 1 doesn't handle branching well. when push branch other master, post-receive hook still syncs master our changes never appear on development site.

problem option 2 git disallows pushing checked-out branch prevent detached head state.

in reading around web, "best practice" solution option 2 goes this:

1) on client push dummy branch

2) on server merge dummy master... buzzzz wrong answer. assume end users don't have shell access server.

so thought, "no problem, create post receive hook this":

#!/bin/bash read oldsha newsha branch git merge $branch 

now here's weird part: when post-receive hook executes get

please, commit changes or stash them before can merge. 

yes, have confirmed master checked-out branch on server, , dummy branch has been updated correctly. when run same command (git merge dummy) directly on server, works fine.

can explain why?

thanks in advance.

edit 1

here results of git status, both pre-merge , post-merge

counting objects: 5, done.                                                                                                                                                             delta compression using 8 threads. compressing objects: 100% (3/3), done. writing objects: 100% (3/3), 307 bytes, done. total 3 (delta 2), reused 0 (delta 0) remote: **** pre merge **** remote: # on branch master remote: # untracked files: remote: #   (use "git add <file>..." include in committed) remote: # remote: #       commit_editmsg remote: #       fetch_head remote: #       head remote: #       orig_head remote: #       config remote: #       description remote: #       hooks/ remote: #       index remote: #       info/ remote: #       logs/ remote: #       objects/ remote: #       packed-refs remote: #       refs/ remote: no changes added commit (use "git add" and/or "git commit -a") remote: error: local changes following files overwritten merge: remote:         index.htm remote: please, commit changes or stash them before can merge. remote: aborting remote: **** post merge **** remote: # on branch master remote: # changes not staged commit: remote: #   (use "git add <file>..." update committed) remote: #   (use "git checkout -- <file>..." discard changes in working directory) remote: # remote: #       modified:   index.htm remote: # remote: # untracked files: remote: #   (use "git add <file>..." include in committed) remote: # remote: #       commit_editmsg remote: #       fetch_head remote: #       head remote: #       orig_head remote: #       config remote: #       description remote: #       hooks/ remote: #       index remote: #       info/ remote: #       logs/ remote: #       objects/ remote: #       packed-refs remote: #       refs/ remote: no changes added commit (use "git add" and/or "git commit -a") 

note can manual git add ., git commit -m "foo" , re-do process same result

in 1 of "duh!" moments, realized use option 1 , pass branch name in attempting option 2.

so, created /home/username/www.git bare repository, cloned /home/username/www , added post-receive hook /home/username/www.git looks this:

#!/bin/bash read oldsha newsha branch git --git-dir="/home/username/www/.git" --work-tree="/home/username/www" pull /home/username/www.git $branch 

then changed remote ssh://username@example.com/home/username/www.git (the bare reop, not working one) , push remote via:

git push remotename branchname 

voila! works.

the actual post-receive code more complex use error traps , variables directory names (so can deployed user), idea.

(be careful distinguish between www/.git , www.git when reading code samples.)


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -