0

This is what we have

  1. Existing website, fully functional and working
  2. Added a new --bare repo to a folder outside of public_html (for example deploy.git)
  3. We use hooks and can push to the public_html using post-recieve
  4. I can't pull all files, only the ones added after the --bare was created (this makes perfect sense to me)

Question

What would be the process to add all of our production files to the repo?

Or have we made a cascade of errors?

Cookra
  • 78
  • 8
  • Can you provide more details for #4? Where are you pulling into and where from? What production files do you want to add? Which repo do you want to add them to? – Code-Apprentice Oct 29 '17 at 14:03
  • Thanks for the swift response! So i'm trying to get my local machine in sync, I also have a Synology NAS which i'd like to make into a local staging.. But that would come from solving this I guess.. As the site was already live with content before I had the bright idea of going down the git route it's those files that are the issue. My hook is set up to take master when it's pushed to the remote. I wasn't sure if I could just add the local files on my machine using git add . then push the whole lot back? Does it overwrite the live files or just add them? – Cookra Oct 29 '17 at 14:23
  • Yes, you can add any files you wish to your local repo and push to the bare one. I assume the hook is in the bare repo which then deploys the site to public_html for production. How do you do this step? Is public_html also a git repo? Or do you just copy the files to public_html without version control there? – Code-Apprentice Oct 29 '17 at 14:27
  • Yep spot on. No repo inside public_html, my understanding is that the hook (inside the bare repo) copies the files and places them into public_html. So what happens for example if I have an Index.php local and obviously in production that is currently not under source control. When I push does this just get overridden? – Cookra Oct 29 '17 at 14:36
  • If your hook uses the native OS command to copy files, then you will get whatever behavior that command provides. For example, `cp` on a Linux machine will overwrite files by default. If you are overwriting a file with one that has the exact same content, then there should not be any problems. – Code-Apprentice Oct 29 '17 at 14:38
  • My lack of skill is apparent.. My post-receive looks like this.. #!/bin/sh GIT_WORK_TREE=/home/site/public_html git checkout -f – Cookra Oct 29 '17 at 14:41
  • I suggest creating a new git repo and testing out what happens. You can do this with the "local" repo, "bare" repo and "public_html" all on the same machine. – Code-Apprentice Oct 29 '17 at 14:48
  • Thanks buddy, i'll play around! Top advice! – Cookra Oct 29 '17 at 16:34

1 Answers1

1

For bare repos it is possible to commit directly to a bare repos but the process in pretty involved see committing to a bare git repository.

For your situation I would suggest that you would be best served by simply copying the whole public_html folder to a location where you can add it to your cloned git repo and then push that to the bare repo. So you would do the following

git clone YOUR_CURRENT_BARE_REPO
(Copy all the files from production into the folder)
git add *
git commit -m "adding production base"
git push origin master

Then you've got all your files in place in your bare repo and you and others can continue development from there.

Jeff Richards
  • 2,032
  • 2
  • 18
  • 23
  • Thanks Jeff.. I'm taking a look;) – Cookra Oct 29 '17 at 14:38
  • Does the git clone add all the files that were in the folder before the --bare was created? – Cookra Oct 29 '17 at 14:46
  • No, but it will set you up the git repo with the files that you already have committed. So it gets you ready to commit the rest of your files into your already existing repository – Jeff Richards Oct 29 '17 at 15:28
  • Ok, thanks.. So this is where I am at the moment I think.. The issue or problem i'm trying to fix is getting those files in the repo that were already in public_html before we created the --bare. You and Code-Apprentice have been most helpful btw! It's much appreciated. In short, I suppose what i'd like to do is point my Synology NAS to the remote and pull a complete clone of all the files. I guess we are doing all this in reverse.. – Cookra Oct 29 '17 at 16:36
  • Yeah, if you're starting from zero then you would get everything set up first and then start pushing and all the deployments would happen automatically. But there's a lot of people in your situation, where there is already a running site and they want to transition to a version controlled system. So you are not doing is crazy. I think the main thing is to just get all the files into the local repo and then you're on the good path to push it out from there. Can you see a clear path to get the files into the local repo? – Jeff Richards Oct 29 '17 at 22:27
  • Thanks Jeff, i've taken that on, also followed Code-Apprentice advice and setting up locally.. – Cookra Nov 01 '17 at 00:02