Git commiting changes that happened on the server

I’m either a moron or Dreamhost is rediculously overcomplicated.
I set up a git repo for my Wordpress site, and pushed it to my server. That has been going great.
Then, my I update a plugin on my website instead of on my local server, and a bunch of files were uploaded to the server via FTP, now my local and remote repos are out of sync.

No problem, right? I ssh into my server, and

cd [sitename]
git commit yada yada yada

… and voil… oh. whoops …

fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

Oh, right, the git is in another folder! duh. So, I just

cd ../[sitename].git

git commit 

and…

fatal: this operation must be run in a work tree

WHAT THE HECK MAN?! When I am in the work tree, it says it’s not a git repo, and when I am in the git repo, it says it’s not a work tree! How am I supposed to commit changes on the server?

The only thing I could figure out to do is FTP all the files back to my local server and commit them, and then push them back to the server, but that seems insane.

Typically, a remote repo on Dreamhost (~/[sitename].git) would be a “bare” Git repository. I.e. it has no working files, just versioning data.

If that’s the case, then maybe the simplest scheme is to use a clone of the bare repo as the site’s web directory. I.e. (untested code):

%% Move and backup original ~[sitename]
git clone ~/[sitename].git ~/[sitename]
cd ~[sitename]
git status
% make changes, git-add, etc
git commit
git pull
git push
...

Now you can make changes in either of the two clones (your local clone and ~[sitename] on DH) and push/pull them to/from the central repo (~[sitename].git on DH). Security note: with this scheme it is important to block access to .git in the site’s .htaccess.

Note that this is just one of dozens of ways to do it. Other options are to use Git Worktrees, or Git’s environment variables (GIT_DIR and GIT_WORK_TREE).

1 Like

OK, I think I’m following you. That seems like an obvious solution. I guess I’ve never worked with a bare repo before. It’s a lot simpler with other platforms like Pantheon and Platform.sh. I guess I got spoiled. Thanks for the clarification.

This post was flagged by the community and is temporarily hidden.

Oh shoot, but I can’t do that because
~/{sitename] already exists and is not an empty directory.

Ugh, my brain is dead.

Ah, I found my own solution. Just clone the repo into a temp folder, and them move the .git from the temp folder into the [sitename] folder.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.