Can I use git to manage a website even if other people update it without using git?
Asked Answered
S

4

4

So let's say I got a web server that I can access over ftp. Most people update it using dreamweaver, and I update by basically copying and pasting manually between my computer and the server. My question is, can I use git to manage the site (and not have to manually copy/paste), while other people update it using other methods?

  • I can't install much on the server. I would like to only put files on the server to set this up.
  • I do not want to have to manually copy and paste to upload to the server.
  • I do not want to inadvertently undo the changes of others not using git, nor do I want to make them use git.
    • That said, if both me and others edit the website at the same time, I would want to take advantage of git's merging capabilities.

How should I set this up? (Also, what scripts could I put on my computer to make this easier (both hooks and non-hooks)? (I would know how to make them, I just would like tips as what kind I should make for this workflow.))

Note: I use linux, if that matters. (Also, I use git from the command line).

Note: I am fine with doing some stuff manually that normally isn't necessary (such as turning my teammates changes into commits). It is manual copying and pasting I want to avoid.

Semivowel answered 9/1, 2016 at 15:12 Comment(7)
Can you install git and run git commands from the command line on the server? Or is your access limited to ftp?Trix
@Trix FTP is essentially all I got. (I can put a git repo on it though.)Semivowel
I can't think of any way to do this without being able to run git on the server, sorry.Trix
Are you able to ssh into this server?Cootch
@Cootch I do not think so.Semivowel
Oh, and you don't mention: what's your local operating system?Cootch
@Trix I pretty sure its possible (see this). I just want tips on some details of the workflow.Semivowel
C
2

What you can do, while not installing git on the server, is maintaining on your local machine a local copy rsync'ed of the server web site.
If your server supports sftp, you can use csync (without having to install it on the server side): it is better than rsync, and bidirectional.

Then you can have your own git repo, and whenever you want to add or compare changes from the website, you can switch branch, and do:

git --work-tree=/path/to/csync/folder status .

That compare your current repo index and that synchronized local folder which reflects the website.

You have two branches in your git repo, one for your current work and one for incorporating the website in the repo.

You can merge the two locally, and when you are ready, you checkout the repo using the csync'ed folder as a working tree

git --work-tree=/path/to/csync/folder checkout HEAD -- .
Cell answered 9/1, 2016 at 16:10 Comment(16)
Instead of using rsync/csync, could I do git --work-tree=ftp://server/location/folder status . instead?Semivowel
No, git doesn't natively support ftp. There is a git-ftp project if you're interested: git-ftp.github.io/git-ftpCootch
@PyRulez no, hence my csync proposition: no installation required on the server side.Cell
@Cell What if I used some sort of ftp mounting thing? (To make it appear to be a local folder?)Semivowel
@PyRulez if you have that, then my answer would apply too (without needing csync).Cell
@PyRulez but VonC is right: if the website folder is mounted, it should be possible to use git directly. You should make sure that the .git cannot be altered by the other users though.Hendrick
@MauricePerry I was just asking if that could be used instead of csync.Semivowel
@MauricePerry My answer is based on the fact the OP "can't install much on the server", meaning no git. Meaning the ftp folder does not contain a .git folder.Cell
@PyRulez remember: your question specifies that you cannot install much on the server: I assume no git on the server. Hence my proposition using a local git repo, and a working tree you can point to your synchronized folder.Cell
@Cell I am not suggesting your answer is wrong, I am just asking about different ways to use it (such as ftp mounting).Semivowel
@Cell (Still, I personally prefer this to changing the working tree. Your answer is still correct though.)Semivowel
@PyRulez that answer assumes git on the server: it does not apply to your case.Cell
@Cell It doesn't. In step 1, I give a couple of ways of making it like you have git on the server when you in fact, do not.Semivowel
@PyRulezGreat! Let us know if that work out for you.Cell
@Cell Okay (I actually did list csync as one of the options in step 1. The main difference between my and your answer is how nongit users are handled.)Semivowel
@PyRulez all he would need is an ftp server which he already hasHendrick
S
1
  1. Somehow set up a method that you can run git commands (on your computer) that affects the FTP server, as well as being able to push to the FTP server (such as using rsync/csync, mounting the ftp server locally, or this combined with some initial copying and pasting).
  2. In the servers git repo, set receive.denyCurrentBranch to updateInstead, via the command git config receive.denyCurrentBranch "updateInstead". See Push to deploy.
  3. Now, when you push from your local repo the server, if the server has been modified, you will get an error like this
    ! [remote rejected] master -> master (Working directory has unstaged changes) error: failed to push some refs to '../remote'
    
    to resolve this, you must commit changes made by your teammates on the remote server. You may want to cherry-pick this. Then go to step 4.
  4. If the local server is in sync with its git branch, you simply push to it, the it's working tree will also be updated. (Keep in mind you still have to things like doing git pull before git push and such.)
Semivowel answered 9/1, 2016 at 17:30 Comment(0)
A
0

I use two servers on one website for this purporse. Production, with only FTP access and development with full access. I do pushing on development server, where I have post-receive script, which checkouts bare repo to temporary folder, and than calls Python script, which uploads code to FTP. I don't know a way to allow other people to use FTP. You should really tell them to use git, it'll be easier for everybody, and you will also have much better control of the code. If you have this setup, you can have only one branch to push to production server, and others will be just development.

Argentum answered 9/1, 2016 at 16:8 Comment(0)
N
0

I have not done this to see how usable it would be, but you could mount the remote directory using for example curlftpfs. I'd expect this gives you a few alternatives to using it:

  1. Have it unmodified, containing only working files and have the repository (i.e. contents of .git) locally at directory specified by GIT_DIR environment variable. core.worktree should be configured to the ftp mount.
  2. You can have it as a true repository with .git subdirectory, do git init etc.
  3. Have in it a .git file instead of using the GIT_DIR environment variable.
  4. Have it manageable with git worktree, after some manual setup as currently there is no automatic conversion of an existing directory to a worktree.

Much depends on if you are the only git user or if there are others bothered with your private changes in the ftp directory.

Novena answered 11/1, 2016 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.