This 'tutorial' is for my own convenience. Whenever I am launching a new web site I tend to repeat the same procedure. It's much easier to follow it if it's written down at one place. So here it is ... (no more looking at .bash_history and browser history to figure out what I did the last time!)
I am assuming that you have just created your dummy/hello world website, perhaps even by some tool or script (e.g. cPanel's 'new python app' or something similar). The steps you need to take now are the following:
- Create (private) project on GitHub.
- Import the created project in your preferred IDE.
- Clean your (remote) website directory.
Delete all empty/unused directories, if any. - Transfer all remaining files to your project's directory.
Pick your preferred method. For me the easiest is compress/download/uncompress. - Add 'usual' files to .gitignore:
e.g. project files and directories, compiled binaries, server generated temp files, etc. - Add files to git index.
- Commit and push.
We are done with the first part. Since we won't be doing code changes on our web server, we'll configure it in a way that it can only pull from our repository. So, on our server:
- Generate public/private RSA key pair:
- Start ssh-keygen.
- Enter the file name, for example your project's name.
- We won't need the passphrase.
- Add deploy key to your GitHub repository:
Under Settings, click on Deploy keys and copy-paste your public key there. - Authenticate from your server to GitHub via SSH:
ssh -i ~/.ssh/private_key_file -T git@github.com - Since neither the repository nor our destination directory are empty, we will execute the following command sequence (in destination directory!):
git init
git remote add origin git@github.com:username/project.git
git pull
git checkout master -f
git branch --set-upstream-to origin/master
We are done. Now we can add the following bash script for easier pulling from our web server's directory:
#! /bin/bash
eval `ssh-agent -s`
ssh-add ~/.ssh/private_key_file
git pull
That would be all!
P.S.: Don't forget to change file permissions once you sync them!
No comments:
Post a Comment