开发者

What is a good Git strategy for maintaining source code on www.hostingcompany.com/~/mysite.com?

开发者 https://www.devze.com 2023-02-26 22:58 出处:网络
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 iswww.hostingcompany.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:

  1. Make a bare repository (mysite.com.git) and a non-bare repository (mysite.com). In the bare repository, add a post-update hook to git --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.

  2. Make just one repository and:

    1. Detach the head: git checkout master@{0}

    2. Add a post-update hook to git 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).

  3. Make just one repository and:

    1. Turn off the push-to-checked-out-branch check.

    2. Add a post-update hook to git 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消