1

I have a question about how to start using automatic deployments after the git repo on our client's site has been wiped out.

What happened to the repo? The client wanted to use a feature on their hosting provider where they can make copy edits to a staging site and "push" it to the live site. After they pushed edits, the git repo disappeared.

Automatic deployments: We're using git hooks do deployments. Here's a good how-to. Basically, you can make deployments locally using git push <environment> <branch>. When you run this command, git runs the following post-receive hook (site name removed for privacy):

#!/bin/bash
TARGET="/www/[sitename]_571/public"
GIT_DIR="/www/[sitename]_571/private/[sitename].git"
BRANCH="master"

while read oldrev newrev ref
do
        # only checking out the master (or whatever branch you would like to deploy)
        if [[ $ref = refs/heads/$BRANCH ]];
        then
                echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
                git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
        else
                echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
        fi
done

The structure of the remote server is:

/www/[sitename]_571/ -> private -> [sitename].git -> hooks
                                     -> public -> website files + .git

What's the least destructive way to get git back on the live site, so we can start making deployments again?

Thanks!

Jillian Hoenig
  • 137
  • 1
  • 6
  • 28
  • I noticed after posting this that the live server actually does have the git repo intact. My mistake was expecting `git log` to return anything, which is never will with the set up I have. Not sure if my question is still valuable - mods can delete if appropriate. – Jillian Hoenig Sep 09 '21 at 15:09
  • A *repository* is self-contained (in the `.git` directory) and consists of commits and ancillary data. A *checked-out working tree* is the result of extracting one commit; it does not contain the information needed to restore a repository. So you can't go from commit to repository unless you still have the repository, or a clone or backup of it. – torek Sep 09 '21 at 18:12

1 Answers1

0

When you run this command, git runs the following post-receive hook

That means you need to restore a bare repository copy "myrepo.git" on the server, in which you will restore the myrepo.git/hooks/post-receive hook.

Then you can push again, and the hook will, from the bare repo, checkout your site with git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f

You can:

  • make a bundle of your current repository,
  • copy that bundle (one file) to the server, and
  • git clone --bare mybundle myrepo.git on the server.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250