I'll add to this as needed.
Since you have ssh access to the server, start there.
1) Connect via ssh to the production server via Terminal (or iTerm app). cd
to the root of your site (or the directory where you want to track changes).
2) Type the following:
git config --global user.name "SITE NAME Prod Server"
git config --global user.email [email protected]
use company or your email
git init
git add .
git commit -am "initial commit, all files added"
Now you have your site files tracked on your production server. For good practice (and ease), next you'll set up a central repo "hub". (See comments below for some thoughts on this.)
3) Sign up for Bitbucket (or pay for GitHub). Note: you can't put an EE site on a public repo.
4) Back on your production ssh connection, create an ssh public/private key pair.
Type
cd ~
ssh-keygen -t rsa -C "[email protected]"
Follow step 2 of GitHub's helpful instructions: https://help.github.com/articles/generating-ssh-keys#step-2-generate-a-new-ssh-key
5) Copy your key to your computer's clipboard from Terminal
Type
pbcopy < ~/.ssh/id_rsa.pub
6) Add this key to Bitbucket so you can push to their server.
See how: step 6 here.
7) Create an empty repo on Bitbucket.
8) Now let's connect your server's repo to your new Bitbucket repo. Back in Terminal, type:
cd /path/to/your/project
git status
- make sure you are actually in your repo
git remote add origin https://[email protected]/USERNAME/MY-REPO.git
- Use your Bitbucket username and repo short name.
You should see it processing to send the files. After it's done, check Bitbucket and make sure your source files are there now.
9) Pull the repo to your local machine (or staging/dev server). Grab the ssh clone command from Bitbucket for your repo (it will be something like
git clone [email protected]:USERNAME/MY-REPO.git
).
Using terminal, go to your local machine's (or staging/dev server's) directory where you want to add the site files. Note that this will create a root folder, so I usually name my repo folder 'public_html`.
Type your clone command:
git clone [email protected]:USERNAME/MY-REPO.git public_html
10) To be able push to Bitbucket from your local machine (or staging/dev server), follow steps 4-6 for your local machine (or staging/dev server).
From here, you are connected from local to production.
11) Add a .gitignore file to your local root directory (in this example, /public_html/.gitignore) to ignore all upload images, media and cache (and whatever else you don't want to track). Don't ignore the .gitignore file because you want it added to your other environments too.
Example .gitignore file for EE.
If you find that your newly ignored files are still being tracked, try this:
git commit -am "your commit message"
(you need to first commit current changes)
git rm -r --cached .
(Or if you just want to cherry pick a file: git rm --cached path/to/file/to/ignore
)
git add .
git commit -m "fixed untracked files"
12) Add
Focus Lab's EE master config (follow their instructions) paying special attention to set the correct
production and local database info.
If you have a team and each developer will be working on the site with his/her own local database, it is helpful to make a copy of config.local.php (rename to EXAMPLE.config.local.php), then ignore config.local.php so the local db settings are not committed and pushed.
13) Export your live site's database and import it into your local site's database.
Do whatever other steps you may need to get your local site running properly. Sync upload directories and/or templates in EE, as needed.
You should be running an exact copy of your live site now.
14) Once you have your local site running with the Master Config, commit those changes.
git commit -am "message describing changes for this commit"
Make changes locally, commit, push (
git push origin master
). Then pull from your server via ssh connection (
git pull origin master
) when you're ready to make those changes live. Or setup an auto-deploy hook/action for your server. Any database changes you make locally will have to replicated on the live site, so make careful note of them!