In response to my previous post on using Git while developing a HTML / CSS site, I thought i’d show how easy it is to deploy changes that I’ve made to a site.
So, after making changes to the code of a site on my local machine, I open up the command line (and change directory to where my project lives) and do the following:
git commit -a -m 'This text describes the changes made since the previous commit'
This commits any changes that I’ve made. The
-a option indicates that you’re committing all of the changes made to files that are already included in your Git repository. If you need to only commit changes made to certain files, you can leave off the
-a option, and instead stage the files individually with a
git add command. If you have added new files, you will need to add them to the repository with a
git add. The
-m option just indicates that you are adding a message to the commit. If you leave it off, Git will prompt you for it.
This pushes the code changes to the remote repository, in my case, Github. Git already knows my username for Github, and uses a public key to securely connect with Github.
This command connects to my web host via SSH. I have all of the login details saved as an alias, and it uses my public key to connect securely. Note: before doing the next command, you will need to change directory to where your site lives on your live server.
This pulls the changes from Github into the live site. Optionally, you could do a
git fetch to retrieve updated info from Github, and then
git status to compare the modified code from Github with the code currently on your live site. This will tell you how many commits behind your live site is, and what kinds of changes have been made.
And that’s it! It is very simple, and all done in the command line. I don’t at all miss the days of manually backing up your files, and then manually copying files via a FTP client. Git makes things much more automated, easy, and secure.