> m o ok.c o b e w o w w. w w < ok o B e w! o W m o d fr a o nl w o D For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. Contents at a Glance About the Authors....................................................................................................xvii About the Technical Reviewer................................................................................xviii About the Cover Image Artist...................................................................................xix Acknowledgments......................................................................................................xx Introduction................................................................................................................xxi Chapter 1: Are You Set Up? Creating a Basic Development Environment.............1 Chapter 2: In the Beginning There Were Just Files.................................................25 Chapter 3: Meet the Current Players in the Game: SVN, Git, and Mercurial.........33 Chapter 4: The Benefits of Version Control.............................................................75 Chapter 5: I Don’t Like Terminal; Which Programs Can I Use?.............................91 Chapter 6: You Mean I Can Version Control Everything?!...................................175 Chapter 7: What Can Make My Life Easier?...........................................................193 Chapter 8: I Have a Conflict: What Can I Do?........................................................221 Chapter 9: I’m Feeling Brave; Can I Do This With Terminal?...............................243 Chapter 10: How to Create a Server........................................................................279 Chapter 11: I Don’t Have a Server, What Other Options Do I Have? ...................293 Chapter 12: Why Branching Is Great......................................................................323 Chapter 13: Hooks, and Why They Can Be Useful................................................341 Chapter 14: Upgrading from CVS and Converting Repositories .........................359 Appendix: Terminal Commands..............................................................................369 Index ..........................................................................................................................381 iv INTRODUCTION Introduction Since you happen to be reading through the opening pages of Foundation Version Control for Web Developers then it’s safe to say you have some interest in finding out a little bit more about version control. It may be true that this new interest isn’t actually your own, but instead comes from a friend, colleague, or employer who thinks getting a bit more knowledge on the subject would be beneficial to you. Either way, throughout the course of this book you’ll be walked through the basics of version control using Subversion (SVN), Mercurial, and Git, getting to know each of them a little better as the chapters go on. I’ll cover setting up a development environment first, just in case you’re really new to the development scene, then the programs you can use for versioning your code (Chapter 5), and even how to dive into Terminal and all your versioning needs with commands (Chapter 9). Don’t worry if any of this seems daunting. As you progress through the chapters you’ll feel your confidence in version control growing, and before long you’ll be a versioning master! Who this book is for Foundation Version Control for Web Developers is a book to help those with little to no knowledge of version control get a leg up on one of key components of modern-day development. Whether you are just getting started in the field, a pro who hasn’t been versioning code until now, or even a designer wanting to expand your knowledge of the field, this book is for you. And whether you’re a freelancer or a full-time agency worker, you’ll always have a need for versioning your code. Knowing more about your chosen field is always a good thing under any circumstance. How this book is structured As mentioned previously, I’ll start off by showing you how to get a development environment of PHP and MySQL set up on your Windows, Mac, or Ubuntu machine. In Chapter 2, you’ll be learning about what version control actually is and why it’s so important, as well as some history on where the books featured systems came from. Then in Chapter 3, it’ll be time to get SVN, Mercurial, and Git installed on your machine, to get you ready for the rest of the book and versioning your code in general. Chapter 4 will introduce the real benefits of version control, showing many other potential situations where having access to some kind of versioning system would make life so much easier. Next, you’ll dive into the world of programs you can utilize to harness the power of version control, without having to go near a Terminal window! The level will come down a little in Chapter 6, where you’ll learn that you shouldn’t version everything using these systems, and I’ll show you some alternatives, just in case you have a need for it. In Chapter 7, I’ll try and make your life a little easier by showing how you can integrate version control into some of your favorite development applications and take you on a tour of the features for those that already boost integration. Conflict management is the topic of Chapter 8, showing how to resolve the pesky conflicts that you’ll get from time to time, both in the code and using applications. The applications will go away in Chapter 9, where I’ll take you into Terminal and show how to get your version control on with just the commands you need to get started! With your confidence from the previous chapter, it’ll be time to create your own server, which you can use to store all of those remote repositories xxi INTRODUCTION you’ll want to be using! If that isn’t your thing, then Chapter 11 will be just right for you, in which I’ll cover some of the packages out there that have done the hard work for you and created some great repository hosting services, with all the trimmings. In Chapter 12, Ian Oxley will be taking you through why branching is so awesome, and how to go about utilizing those awesome features. Ian will then lead you into Chapter 14, detailing what commit hooks are and how they can be really useful in your versioning workflow. Finally, in the last chapter in the book I’ll bring you in for the close, with a chapter on upgrading your CVS repository, if you happen to have one, and how to migrate from SVN to Git or Mercurial, if you fancy a change. What will I need? As far the book goes, as long as you have either an up-to-date Mac, PC, or Ubuntu installation, you’ll have no problem using these great applications and bettering your version control knowledge. The only other thing you’ll need is a desire to learn some awesome new techniques and to make sure that your code stays safe and is backed up. Contacting Chris Kemper Chris Kemper can be contacted at either [email protected] or through his Twitter account @chrisdkemper. xxii Chapter 1 Are You Set Up? Creating a Basic Development Environment Have you ever experienced that moment when someone asks you to help out with a current website build, or to help start off a new project, and you realize you just aren’t set up to cope with it? If you’ve ever been caught in this situation, without even knowing where to start, this chapter will help. Although I’m not going to cover how to get you set up with every development environment, I will get you started with the most common. Knowing you have it all set up and working on your machine can give you the confidence you need to grab that new project by the horns. I know you’re itching to get started learning about version control, even if you’re not set up yet, but you have to be patient. If you’re just getting into the whole writing code thing, don’t worry, I’ll be guiding you through the entire process from start to finish. You don’t have to worry about any developers judging your knowledge here; we’re all starting from the same page. You can work through it at your own pace, or even come back to it if need be. Even though people always try and avoid alienating new colleagues, or even people new to the industry, you can still feel self-conscious when it comes to asking for help or just taking those first steps. The web design field, by nature, is very friendly, but it can still be nerve-wracking for some people to have to ask someone about the basics. If you are one of those people, this book will help you. You can try all setting this all up at home, on your own time, without any fear. Plus, when you’re through, I’ll bet you’ll be able to show everyone else a thing or two. When it comes to developing anything, whether it’s a website, an application, or a framework, you might be using a totally different environment than the one I’m about to walk you through. To get us all on the 1 Chapter 1 same page, I’ll take you through a basic PHP/MySQL/Apache setup—or as it’s known in the Linux world, a LAMP stack (Linux, Apache, MySQL, and PHP). I’ve chosen this environment because it’s a great way to get started in development and, just like Brick Tamland from the movie Anchor Man, I love LAMP. (I’m sure you’ve heard of Wordpress. Well that’s built using PHP and MySQL; a lot of designers and developers who are looking to get started with web design, find trying to build a blog for themselves a good place to start. You can find a few good books on the subject, such as Blog Design Solutions by Andy Budd (Friends of ED, 2008), which I highly recommend. Now comes the time to start getting ready to go, and the first stop is with Windows. As Barney Stinson on television’s “How I Met Your Mother” would say, “new is always better,” so I’ll be showing you how to get set up in Windows 7. Don’t worry if you’re not running Windows 7. These steps will work regardless of your version of Windows (as long as you’re not running Windows 98). If there’s something you should know, I’ll be sure to tell you. Once I’ve shown you how to get started with Windows it’ll be time to take a trip to Mac town. I’ll get you all set up on your Mac, step by step, so it’s nice and simple. For you hardcore programmers out there, I’ll be continuing through to Linux land, in the form of Ubuntu. While going over Ubuntu, I’ll show you how easy it is to apt-get yourself started (it’s a clever Linux pun, you’ll see). Finally, when you’re all set up, I’ll get into the good stuff: getting your files version controlled. So with that said, it’s time to set up Windows. Microsoft Windows There are a few options available to get you set up on Windows, and a lot of them have a nice and easy install interface. Some of the more popular solutions are Easy PHP, xampp, WAMP, and Wamp Developer Pro. The latter is a paid solution, but all of the previous products are free and open source. If you were to scour the Internet for reviews, you would no doubt find glowing reviews of one solution or another. Although I have no real bias between these packages (I use a Mac), I’ll be using Windows, Apache, MySQL, and PHP (WAMP) for the Windows 7 walkthrough. Don’t let that stop you from trying others, though; once you’ve mastered the techniques in this book you’ll be able to try any of the solutions I’ve mentioned, or even ones I don’t know about. Getting the package Before you can install anything, you’ll need the package, so jump into your favorite browser (which I hope isn’t Internet Explorer) and head on over to www.wampserver.com. When you land, navigate to the Downloads page. You will have the option of choosing either 32 bit or 64 bit here. If you’re unsure which your system is, open up your computer’s Properties, which you can find by opening up Start, then right- clicking Computer and choosing Properties. As you can see in Figure 1-1, I’m using a 64-bit system, so I’ll be downloading the 64-bit version of the application. 2 Are You Set Up? Creating a Basic Development Environment Figure 1-1. The Windows 7 configuration screen, in this instance showing that the system is 64 bit Getting your install on Once you have the file downloaded and you give it the good old double-click, you’ll see the lovely screen shown in Figure 1-2. Click Next and move onto the license screen, have a nice read, and move on. 3 Chapter 1 Figure 1-2. The first screen of the WAMP installation which also shows the different versions of Apache, MySQL, PHPMyAdmin, and SqlBuddy Once you’ve finished going through the license agreement, you’ll see what’s pictured in Figure 1-3. Figure 1-3. The installation directory for WAMP, which defaults to c:\wamp 4 Are You Set Up? Creating a Basic Development Environment As you can see, the program suggests you install WAMP straight onto C:, not directly into the program files as with most other applications you’d install. I suggest leaving it where it is, because it makes life much easier by giving easy access to the directory. However, you can move the directory to another location by clicking Browse... I used to have my WAMP install onto my D: drive; the main advantage of this is that it is safe from any potential operating system crashes or problems. It also means that if you want to upgrade your system, you can wipe your operating system drive and your sites will all be safe, which is great! Working through Windows prompts Throughout this installation you’ll be seeing a lot of those Windows security prompts that ask for your permission before allowing files to be installed on the system, or if something you’re installing wants to make changes to your system. You can say yes to all of these requests, as they pose no threat to your system. The most important is the firewall prompt, which will ask permission for Apache to be allowed to transfer information through the firewall, which you will encounter once you reach the end of the installation. Be sure to allow this to avoid problems while running sites in your WAMP installation. You’ll then be prompted to choose if you want a desktop shortcut, or if you’d like WAMP to be added to the quick launch bar. Adding either of these gives you a quick link, either on the desktop or the bottom menu bar, to start the application. If you choose not to create the shortcut, you can always start it via the Start menu. You will then see the setup ask for confirmation about all the previous options, and away it goes to copy across all the files. Configuring PHP settings Once that’s all done you’ll be asked to configure your PHP SMTP settings. For the sake of a basic install, and to get you up and running with a basic environment, I would suggest just leaving these as they are. If you’re planning on testing PHP’s mail function or using this machine as a live web server, you won’t really need these settings, so they can be left as default. Choosing the default browser You’ll also be prompted to find your default browser, which is Internet Explorer. If you’d like to change this to another browser, navigate to it via the popup window. If you’re unsure where your browser is located, you can always open the Properties window of a shortcut to it (such as a Start menu item, or Desktop shortcut), which will show you its location, or you can just leave it as the default. It’s possible to change this at a later date, but it requires editing one of the applications configuration files. Don’t let that worry you though; I’ll mention how to do that a little later. If you’d like to use a different browser, such as Firefox, here’s how: when the popup window opens, go back to C:, then Programs Files (x86) ➤ Mozilla Firefox and double-click to select it. (You can see what this folder looks like by checking out Figure 1-4.) Once you’ve selected your default browser (whatever that is) and clicked Next, you’re ready to launch the application. That’s it for the setup. Hooray! 5
Description: