What is a good Git strategy for maintaining source code on www.hostingcompany.com/~/mysite.com?
This is related to Cannot git clone a folder on a server and then edit and git push?
So let's say the hosting company is www.hostingcompany.com
and when I ssh to it, I am in ~
and I will see
~/mysite.com
~/any_other_folders
What is a good Git workflow to version control all source code in ~/mysite.com
, and able to git clone
to my local PC? And so that I can make modification locally, and then issue one line and p开发者_JAVA百科ush to the repo and have all code on ~/mysite.com
up to date?
Is using a git repo, and then sftp
from local PC to ~/mysite.com
a good way? I prefer not to do that as it is harder to see if everything is sync'ed.
Copying the answer straight from the related question where you already got it:
You have two options:
Make a bare repository (
mysite.com.git
) and a non-bare repository (mysite.com
). In the bare repository, add apost-update
hook togit --git-dir=.../mysite.com pull
Note, that you may want to create the non-bare repository by cloning from the bare one with
-s
flag or set up.git/objects/info/alternates
afterwards to avoid copying all the data.Make just one repository and:
Detach the head:
git checkout master@{0}
Add a
post-update
hook togit merge master
The reason here is that git refuses to modify the checked-out branch, but if you uncheckout the branch, you will be able to push. And you will be able to update the working directory from a hook (hook is a script placed in
hooks
directory in the repository). You can either create a separate branch and check out that, or you can use the "detached HEAD" state (as suggested above—git remembers which branch is checked out by having a special reference "HEAD" that points to the branch, but if you check out something, that is not a branch, it is made to point to a revision directly and that's called a "detached branch" and since no branch is checked out, allows you to push to any of them).Make just one repository and:
Turn off the push-to-checked-out-branch check.
Add a
post-update
hook togit reset --hard
to re-checkout the branch when pushed.
This option is only valid for read-only access, because the hook will discard any local changes each time you push.
If it's just check out and have it accessed read-only, the second option is slightly more efficient, but if you run some other commands on the working directory, the first is safer (you can wipe and re-create the working copy without worrying about the main repo). See also this question.
Edit: added third option.
精彩评论