<p>So I get that most of you are frowning at me for not currently using any source control.  I want to, I really do, now that I've spent some time reading the questions / answers here.    I am a hobby programmer and really don't do much more than tinker, but I've been bitten a couple of times now not having the 'time machine' handy...</p>

<p>I still have to decide which product I'll go with, but that's not relevant to this question.</p>

<p>I'm really struggling with the flow of files under source control, so much so I'm not even sure how to pose the question sensibly.</p>

<p>Currently I have a directory hierarchy where all my PHP files live in a Linux Environment.  I edit them there and can hit refresh on my browser to see what happens.</p>

<p>As I understand it, my files now live in a different place. When I want to edit, I check it out and edit away.  But what is my substitute for F5?  How do I test it?  Do I have to check it back in, then hit F5?  I admit to a good bit of trial and error in my work.  I suspect I'm going to get tired of checking in and out real quick for the frequent small changes I tend to make.  I have to be missing something, right?</p>

<p>Can anyone step me through where everything lives and how I test along the way, while keeping true to the goal of having a 'time machine' handy?</p>

[{'answer_id': 67081, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 3, 'selected': False, 'text': '<p>Eric Sink has a great <a href="http://www.ericsink.com/scm/source_control.html" rel="noreferrer">series of posts</a> on source control basics.  His company (Sourcegear) makes a source control tool called Vault, but the how-to is generally pretty system agnostic.</p>\n'}, {'answer_id': 67084, 'author': 'Jason Cohen', 'author_id': 4926, 'author_profile': 'https://Stackoverflow.com/users/4926', 'pm_score': 1, 'selected': False, 'text': '<p>You still have all the files on your hard drive, ready for F5!</p>\n\n<p>The difference is that you can "checkpoint" your files into the repository.  Your daily life doesn\'t have to change at all.</p>\n'}, {'answer_id': 67090, 'author': 'James A. N. Stauffer', 'author_id': 6770, 'author_profile': 'https://Stackoverflow.com/users/6770', 'pm_score': 1, 'selected': False, 'text': '<p>You can do a "checkout" to the same directory where you currently work so that doesn\'t have to change.  Basically your working directory doesn\'t need to change.</p>\n'}, {'answer_id': 67094, 'author': 'Loren Segal', 'author_id': 6436, 'author_profile': 'https://Stackoverflow.com/users/6436', 'pm_score': 1, 'selected': False, 'text': '<p>This is a wildly open ended question because how you use a SCM depends heavily on which SCM you choose. A distributed SCM like git works very differently from a centralized one like Subversion.</p>\n\n<p>svn is way easier to digest for the "new user", but git can be a little more powerful and improve your workflow. Subversion also has really great docs and tool support (like trac), and an online book that you should read:</p>\n\n<p><a href="http://svnbook.red-bean.com/" rel="nofollow noreferrer">http://svnbook.red-bean.com/</a></p>\n\n<p>It will cover the basics of source control management which will help you in some way no matter which SCM you ultimately choose, so I recommend skimming the first few chapters.</p>\n\n<p>edit: Let me point out <em>why</em> people are frowning on you, by the way: SCM is more than simply a "backup of your code". Having "timemachine" is nothing like an SCM. With an SCM you can go back in your change history and see what you actually changed and when which is something you\'ll <em>never</em> get with blobs of code. I\'m sure you\'ve asked yourself on more than one occasion: "how did this code get here?" or "I thought I fixed that bug"-- if you did, thats why you need SCM.</p>\n'}, {'answer_id': 67095, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 0, 'selected': False, 'text': '<p>If you are using Subversion, you check out your files <em>once</em> . Then, whenever you have made big changes (or are going to lunch or whatever), you <em>commit</em> them to the server. That way you can keep your old work flow by pressing F5, but every time you <em>commit</em> you save a copy of all the files in their current state in your SVN-repository.</p>\n'}, {'answer_id': 67100, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': 0, 'selected': False, 'text': "<p>Depending on the source control system, 'checkout' may mean different things.  In the SVN world, it just means retrieving (could be an update, could be a new file) the latest copy from the repository.  In the source-safe world, that generally means updating the existing file <em>and locking it.</em>  The text below uses the SVN meaning:</p>\n\n<p>Using PHP, what you want to do is checkout your entire project/site to a working folder on a test apache site.  You should have the repository set up so this can happen with a single checkout, including any necessary sub folders.  You checkout your project to set this up <em>one time</em>.  </p>\n\n<p>Now you can make your changes and hit F5 to refresh as normal.  When you're happy with a set of changes to support a particular fix or feature, you can <em>commit</em> in as a unit (with appropriate comments, of course).  This puts the latest version in the repository.</p>\n\n<p>Checking out/committing one file at a time would be a hassle.</p>\n"}, {'answer_id': 67110, 'author': 'Matt Dawdy', 'author_id': 232, 'author_profile': 'https://Stackoverflow.com/users/232', 'pm_score': 2, 'selected': False, 'text': '<p>Actually, your files, while stored in a source repository (big word for another place on your hard drive, or a hard drive somewhere else), can also exist on your local machine, too, just where they exist now.</p>\n\n<p>So, all files that aren\'t checked out would be marked as "read only", if you are using VSS (not sure about SVN, CVS, etc).  So, you could still run your website by hitting "F5" and it will reload the files where they currently are.  If you check one out and are editing it, it becomes NOT read only, and you can change it.</p>\n\n<p>Regardless, the web server that you are running will load readonly/writable files with the same effect.</p>\n'}, {'answer_id': 67111, 'author': 'Max Caceres', 'author_id': 4842, 'author_profile': 'https://Stackoverflow.com/users/4842', 'pm_score': 0, 'selected': False, 'text': '<p>Depends on the source control system you use. For example, for subversion and cvs your files can reside in a remote location, but you always check out your own copy of them locally. This local copy (often referred to as the <code>working copy</code>) are just regular files on the filesystem with some meta-data to let you upload your changes back to the server.</p>\n\n<p>If you are using Subversion here\'s a <a href="http://www.germane-software.com/~ser/R_n_R/subversion.html" rel="nofollow noreferrer">good tutorial</a>.</p>\n'}, {'answer_id': 67118, 'author': 'Forgotten Semicolon', 'author_id': 1960, 'author_profile': 'https://Stackoverflow.com/users/1960', 'pm_score': 3, 'selected': False, 'text': "<ol>\n<li>Don't edit your code on production.</li>\n<li>Create a development environment, with the appropriate services (apache w/mod_php).</li>\n<li>The application directory within your dev environment is where you do your work.</li>\n<li>Put your current production app in there.</li>\n<li>Commit this directory to the source control tool. (now you have populated source control with your application)</li>\n<li>Make changes in your new development environment, hitting F5 when you want to see/test what you've changed.</li>\n<li>Merge/Commit your changes to source control.</li>\n</ol>\n"}, {'answer_id': 67152, 'author': 'Sietse', 'author_id': 6400, 'author_profile': 'https://Stackoverflow.com/users/6400', 'pm_score': 1, 'selected': False, 'text': '<p>You don\'t "have" to change your workflow in a drastic way. You could, and in some cases you should, but that\'s not something version control dictates.</p>\n\n<p>You just use the files as you would normally. Only under version control, once you reach a certain state of "finished" or at least "working" (solved an issue in your issue tracker, finished a certain method, tweaked something, etc), you check it in. </p>\n\n<p>If you have more than one developer working on your codebase, be sure to update regularly, so you\'re always working against a recent (merged) version of the code.</p>\n'}, {'answer_id': 67227, 'author': 'wds', 'author_id': 10098, 'author_profile': 'https://Stackoverflow.com/users/10098', 'pm_score': 0, 'selected': False, 'text': '<p>A source control system is generally a storage place for your files and their history and usually separate from the files you\'re currently working on. It depends a bit on the type of version control system but suppose you\'re using something CVS-like (like subversion), then all your files will live in two (or more) places. You have the files in your local directory, the so called "working copy" and one in the repository, which can be located in another local folder, or on another machine, usually accessed over the network. Usually, after the first import of your files into the repository you check them out under a working folder where you continue working on them. I assume that would be the folder where your PHP files now live.</p>\n\n<p>Now what happens when you\'ve checked out a copy and you made some non-trivial changes that you want to "save"? You simply commit those changes in your working copy to the version control system. Now you have a history of your changes. Should you at any point wish to go back to the version at which you committed those changes, then you can simply revert your working copy to an older revision (the name given to the set of changes that you commit at once).</p>\n\n<p>Note that this is all very CVS/SVN-specific, as GIT would work slightly different. I\'d recommend starting with subversion and reading the first few chapters of the very excellent <a href="http://svnbook.red-bean.com/" rel="nofollow noreferrer">SVN Book</a> to get you started.</p>\n'}, {'answer_id': 67240, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>This is all very subjective depending on the the source control solution that you decide to use.  One that you will definitely want to look into is Subversion.</p>\n\n<p>You mentioned that you\'re doing PHP, but are you doing it in a Linux environment or Windows?  It\'s not really important, but what I typically did when I worked in a PHP environment was to have a production branch and a development branch.  This allowed me to configure a cron job (a scheduled task in Windows) for automatically pulling from the production-ready branch for the production server, while pulling from the development branch for my dev server.</p>\n\n<p>Once you decide on a tool, you should really spend some time learning how it works.  The concepts of checking in and checking out don\'t apply to all source control solutions, for example.  Either way, I\'d highly recommend that you pick one that permits branching.  <a href="http://www.infoq.com/articles/agile-version-control" rel="nofollow noreferrer">This article</a> goes over a great (in my opinion) source control model to follow in a production environment.</p>\n\n<p>Of course, I state all this having not "tinkered" in years.  I\'ve been doing professional development for some time and my techniques might be overkill for somebody in your position.  Not to say that there\'s anything wrong with that, however.</p>\n'}, {'answer_id': 67467, 'author': 'Sebastian Rittau', 'author_id': 7779, 'author_profile': 'https://Stackoverflow.com/users/7779', 'pm_score': 1, 'selected': False, 'text': "<p>Here is the general workflow that you'd use with a non-centralized source control system like CVS or Subversion: At first you import your current project into the so-called repository, a versioned storage of all your files. Take care only to import hand-generated files (source, data files, makefiles, project files). Generated files (object files, executables, generated documentation) should not be put into the repository.</p>\n\n<p>Then you have to check out your working copy. As the name implies, this is where you will do all your local edits, where you will compile and where you will point your test server at. It's basically the replacement to where you worked at before. You only need to do these steps once per project (although you could check out multiple working copies, of course.)</p>\n\n<p>This is the basic work cycle: At first you check out all changes made in the repository into your local working copy. When working in a team, this would bring in any changes other team members made since your last check out. Then you do your work. When you've finished with a set of work, you should check out the current version again and resolve possible conflicts due to changes by other team members. (In a disciplined team, this is usually not a problem.) Test, and when everything works as expected you commit (check in) your changes. Then you can continue working, and once you've finished again, check out, resolve conflicts, and check in again. Please note that you should only commit changes that were tested and work. How often you check in is a matter of taste, but a general rule says that you should commit your changes at least once at the end of your day. Personally, I commit my changes much more often than that, basically whenever I made a set of related changes that pass all tests.</p>\n"}, {'answer_id': 67787, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>I just want to add that the system that I think was easiest to set up and work with was <a href="http://www.selenic.com/mercurial/wiki/" rel="nofollow noreferrer">Mercurial</a>. If you work alone and not in a team you just initialize it in your normal work folder and then go on from there. The normal flow is to edit any file using your favourite editor and then to a checkin (commit).\nI havn\'t tried GIT but I assume it is very similar. Monotone was a little bit harder to get started with. These are  all distributed source control systems.</p>\n'}, {'answer_id': 67902, 'author': 'Wedge', 'author_id': 332, 'author_profile': 'https://Stackoverflow.com/users/332', 'pm_score': 0, 'selected': False, 'text': "<p>It sounds like you're asking about how to use source control to manage releases.</p>\n\n<p>Here's some general guidance that's not specific to websites:</p>\n\n<ul>\n<li>Use a local copy for developing changes</li>\n<li>Compile (if applicable) and test your changes before checking in</li>\n<li>Run automated builds and tests as often as possible (at least daily)</li>\n<li>Version your daily builds (have some way of specifying the exact bits of code corresponding to a particular build and test run)</li>\n<li>If possible, use separate branches for major releases (or have a development and a release branch)</li>\n<li>When necessary, stabilize your code base (define a set of tests such that passing all of those tests means you are confident enough in the quality of your product to release it, then drive toward 0 test failures, i.e. ban any checkins to the release branch other than fixes for the outstanding issues)</li>\n<li>When you have a build which has the features you want and has passed all of the necessary tests, deploy it.</li>\n</ul>\n\n<p>If you have a small team, a stable product, a fast build, and efficient, high-quality tests then this entire process might be 100% automated and could take place in minutes.</p>\n"}, {'answer_id': 68112, 'author': 'Kalid', 'author_id': 109, 'author_profile': 'https://Stackoverflow.com/users/109', 'pm_score': 1, 'selected': False, 'text': '<p>Great question. With source control you can still do your "F5" refresh process. But after each edit (or a few minor edits) you want to check your code in so you have a copy backed up.</p>\n\n<p>Depending on the source control system, you don\'t have to explicitly check out the file each time. Just editing the file will check it out. I\'ve written <a href="http://betterexplained.com/articles/a-visual-guide-to-version-control/" rel="nofollow noreferrer">a visual guide to source control</a> that many people have found useful when grokking the basics.</p>\n'}, {'answer_id': 68240, 'author': 'willurd', 'author_id': 1943957, 'author_profile': 'https://Stackoverflow.com/users/1943957', 'pm_score': 0, 'selected': False, 'text': '<p>I recommend <a href="http://svnbook.red-bean.com/" rel="nofollow noreferrer">Subversion</a>. Setting up a repository and using it is actually fairly trivial, even from the command line. Here\'s how it would go:</p>\n<h1>if you haven\'t setup your repo (repository)</h1>\n<h3><strong>1)</strong> Make sure you\'ve got Subversion installed on your server</h3>\n<pre><code>$ which svn\n/usr/bin/svn\n</code></pre>\n<p><em>which</em> is a tool that tells you the path to another tool. if it returns nothing that tool is not installed on your system</p>\n<h3><strong>1b)</strong> If not, get it</h3>\n<pre><code>$ apt-get install subversion\n</code></pre>\n<p><em>apt-get</em> is a tool that installs other tools onto your system</p>\n<p>If that\'s not the right name for subversion in apt, try this</p>\n<pre><code>$ apt-cache search subversion\n</code></pre>\n<p>or this</p>\n<pre><code>$ apt-cache search svn\n</code></pre>\n<p>Find the right package name and install it using <em>apt-get install packagename</em></p>\n<h3><strong>2)</strong> Create a new repository on your server</h3>\n<pre><code>$ cd /path/to/directory/of/repositories\n$ svnadmin create my_repository\n</code></pre>\n<p><em>svnadmin create reponame</em> creates a new repository in the present working directory (<em>pwd</em>) with the name <em>reponame</em></p>\n<p>You are officially done creating your repository</p>\n<br />\n<h1>if you have an existing repo, or have finished setting it up</h1>\n<h3><strong>1)</strong> Make sure you\'ve got Subversion installed on your local machine per the instructions above</h3>\n<h3><strong>2)</strong> Check out the repository to your local machine</h3>\n<pre><code>$ cd /repos/on/your/local/machine\n$ svn co svn+ssh://www.myserver.com/path/to/directory/of/repositories/my_repository\n</code></pre>\n<p><em>svn co</em> is the command you use to check out a repository</p>\n<h3><strong>3)</strong> Create your initial directory structure (optional)</h3>\n<pre><code>$ cd /repos/on/your/local/machine\n$ cd my_repository\n$ svn mkdir branches\n$ svn mkdir tags\n$ svn mkdir trunk\n$ svn commit -m "Initial structure"\n</code></pre>\n<p><em>svn mkdir</em> runs a regular <em>mkdir</em> and creates a directory in the present working directory with the name you supply after typing <em>svn mkdir</em> and then adds it to the repository.</p>\n<p><em>svn commit -m &quot;&quot;</em> sends your changes to the repository and updates it. Whatever you place in the quotes after <em>-m</em> is the comment for this commit (make it count!).</p>\n<p>The &quot;working copy&quot; of your code would go in the <em>trunk</em> directory. <em>branches</em> is used for working on individual projects outside of trunk; each directory in <em>branches</em> is a copy of <em>trunk</em> for a different sub project. <em>tags</em> is used more releases. I suggest just focusing on <em>trunk</em> for a while and getting used to Subversion.</p>\n<br />\n<h1>working with your repo</h1>\n<h3><strong>1)</strong> Add code to your repository</h3>\n<pre><code>$ cd /repos/on/your/local/machine\n$ svn add my_new_file.ext\n$ svn add some/new/directory\n$ svn add some/directory/*\n$ svn add some/directory/*.ext\n</code></pre>\n<p>The second to last line adds every file in that directory. The last line adds every file with the extension .ext.</p>\n<h3><strong>2)</strong> Check the status of your repository</h3>\n<pre><code>$ cd /repos/on/your/local/machine\n$ svn status\n</code></pre>\n<p>That will tell you if there are any new files, and updated files, and files with conflicts (differences between your local version and the version on the server), etc.</p>\n<h3><strong>3)</strong> Update your local copy of your repository</h3>\n<pre><code>$ cd /repos/on/your/local/machine\n$ svn up\n</code></pre>\n<p>Updating pulls any new changes from the server you don\'t already have</p>\n<p><em>svn up</em> does care what directory you\'re in. If you want to update your entire repository, makre sure you\'re in the root directory of the repository (above trunk)</p>\n<hr />\n<p>That\'s all you really need to know to get started. For more information I recommend you check out the <a href="http://svnbook.red-bean.com/" rel="nofollow noreferrer">Subversion Book</a>.</p>\n'}, {'answer_id': 68369, 'author': 'RFelix', 'author_id': 10582, 'author_profile': 'https://Stackoverflow.com/users/10582', 'pm_score': 1, 'selected': False, 'text': '<p>I would recommend a distributed version control system (mercurial, git, bazaar, darcs) rather than a centralized version control system (cvs, svn). They\'re much easier to setup and work with.</p>\n\n<p>Try mercurial (which is the VCS that I used to understand how version control works) and then if you like you can even move to git.</p>\n\n<p>There\'s a really nice introductory tutorial on Mercurial\'s homepage: <a href="http://www.selenic.com/mercurial/wiki/index.cgi/UnderstandingMercurial" rel="nofollow noreferrer">Understanding Mercurial</a>. That will introduce you to the basic concepts on VCS and how things work. It\'s really great. After that I suggest you move on to the Mercurial tutorials: <a href="http://www.selenic.com/mercurial/wiki/index.cgi/Tutorial" rel="nofollow noreferrer">Mercurial tutorial page</a>, which will teach you how to actually use Mercurial. Finally, you have a free ebook that is a really great reference on how to use Mercurial: <a href="http://hgbook.red-bean.com/" rel="nofollow noreferrer">Distributed Revision Control with Mercurial</a></p>\n\n<p>If you\'re feeling more adventurous and want to start off with Git straight away, then this free ebook is a great place to start: <a href="http://www-cs-students.stanford.edu/~blynn/gitmagic/" rel="nofollow noreferrer">Git Magic</a> (Very easy read)</p>\n\n<p><strong>In the end</strong>, no matter what VCS tool you choose, what you\'ll end up doing is the following:</p>\n\n<ol>\n<li>Have a repository that you don\'t manually edit, it only for the VCS</li>\n<li>Have a working directory, where you make your changes as usual.</li>\n<li>Change what you like, press F5 as many times as you wish. When you like what you\'ve done and think you would like to save the project the way it is at that very moment (much like you would do when you\'re, for example, writing something in Word) you can then commit your changes to the repository.</li>\n<li>If you ever need to go back to a certain state in your project you now have the power to do so.</li>\n</ol>\n\n<p>And that\'s pretty much it.</p>\n'}]
['https://Stackoverflow.com/questions/67069', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1444/']