0

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 push 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.

Community
  • 1
  • 1
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • possible duplicate of [Cannot git clone a folder on a server and then edit and git push?](http://stackoverflow.com/questions/5703324/cannot-git-clone-a-folder-on-a-server-and-then-edit-and-git-push) – R. Martinho Fernandes Apr 18 '11 at 13:51

1 Answers1

2

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.

Community
  • 1
  • 1
Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
  • is `mysite.com.git` a directory or a file? Do we create it using `mkdir mysite.com.git`, `cd mysite.com.git`, `git init --bare`, `cd ../mysite.com`, and then `git init`, `git add .`, `git commit -m "ok"`, `git push ../mysite.com.git master` ? – nonopolarity Apr 18 '11 at 13:55
  • First option is the best, in my opinion – manojlds Apr 18 '11 at 16:50
  • @動靜能量: `mysite.com.git` is a bare repository, so a directory. Yes, you create it as you say. It is a common convention to name bare repositories with `.git` suffix. – Jan Hudec Apr 19 '11 at 06:44