Posts Tagged: webdev

Text

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.

git push

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.

ssh web

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.

git pull

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.

Text

Git Is Awesome!

I recently learned how to use the Git version control system, and it has been a huge help not only when programming, but also with simple HTML / CSS development. If you’ve never used Git, here is a very brief overview:

Git is a command line tool that keeps track of the changes you make to files. As you develop your code, you make “commits” at various “checkpoints” that you want to save. You can save commits as often as you would like, and generally, the more often the better. At any time, you can revert back to a previous commit with a simple command. When you do this, Git will change all of your files back to how they were when you saved that commit. Git is very powerful in that it can also undo only specific commits. So, say you have commit 1, 2, 3, 4, and 5, and you want to un-do only what you did between commit 2 and 3. Git can do that.

Git also allows you to set up remote repositories. Generally, your repository will live in three places- your local computer (for development), a repository host like Github, and your live site. After making changes on your local computer, a simple command pushes all of your changes to the remote host. When you are ready to implement the changes on your live site, another simple command will pull those changes from the remote host onto your live site.

Obviously, this is a very powerful tool, and is quite useful not only for programmers, but also for web developers.

Here are a few of the benefits of using Git with your HTML/CSS site:

Experimentation without worry.

If you’re using Git, you can very easily revert changes that you haven’t (or have) committed yet. So if you want to play around a bit with your code, you can easily do so without having to worry about messing up your site.

Easiliy fix mistakes.

Ever accidentally delete a few lines of code, and can’t even quite figure out what all you deleted? If you’re using Git and you commit often, this is not a concern.

No more copying files!

If you’re using Git, you no longer have to go and re-upload files that you’ve changed. Git handles it all for you, via very simple commands.

Hassle-free backups.

Backing up your site is always a good idea. With Git, every time you make a commit, you have a backup of that point. Also, when you’re using a remote host, all of your commits are stored there. So if your computer’s hard drive is wiped out, a simple pull command will restore everything, even all of your commit history.

I highly recommend Github- it has awesome instructions for getting started with Git, and will host public repositories for free. 

You can learn more about Git here: http://git-scm.com/

Here is a video that does a pretty good job of explaining how to use Git: http://youtu.be/DQUcmNO4diQ