Source control

Source control, also known as version control, stores software code files with a detailed history of every modification made to those files.

Why is source control necessary?

Version control systems allow developers to modify code without worrying about permanently screwing something up. Unwanted changes can be easily rolled back to previous working versions of the code.

Source control also makes team software development easier. One developer can combine her code modifications with other developers' code through diff views that show line-by-line changes then merge the appropriate code into the main code branch.

Version control is a necessity on all software projects regardless of development time, codebase size or the programming language used. Every project should immediately begin by using a version control system such as Git or Mercurial.

Source control during deployment

Pulling code during a deployment is a potential way source control systems fit into the deployment process.

App deployment uses a server to pull from the source control system.

Note that some developers recommend deployment pipelines package the source code to deploy it and never have a production environment touch a source control system directly. However, for small scale deployments it's often easiest to pull from source code when you're getting started instead of figuring out how to wrap the Python code in a system installation package.

Source control projects

Numerous source control systems have been created over the past several decades. In the past, proprietary source control software offered features tailored to large development teams and specific project workflows. However, open source systems are now used for version control on the largest and most complicated software projects in existence. There's no reason why your project should use anything other than an open source version control system in today's Python development world. The two primary choices are:

  • Git is a free and open source distributed version control system.

  • Mercurial is similar to Git, also a free and open source distributed version control system.

  • Subversion is a centralized system where developers must check files in and out of the hosted repository to minimize merge conflicts.

Hosted source control services

Git and Mercurial can be downloaded and run on your own server. However, it's easy and cheap to get started with a hosted version control service. You can transition away from the service at a later time by moving your repositories if your needs change. A couple of recommended hosted version control services are:

  • GitLab has both a self-hosted version of its open source software as well as their hosted version with pricing for businesses that need additional hosting support.

  • GitHub provides free open source repositories and paid private repositories for Git.

  • BitBucket also has free Git and Mercurial repositories for open projects, but adds private repositories for up to five users. Users pay for hosting private repositories with more than five users.

General source control resources

Git resources

The following resources provide a good start for developers new to source control and Git. There is also an entire page on using Git with Python with many more links sorted by categories such as solving tactical issues and Git workflows.

  • Git in Six Hundred Words is a clear and concise essay explaining the fundamental concepts of Git.

  • A Hacker's Guide to Git covers the basics as well as more advanced Git commands while explaining each step along the way.

  • Think like a Git is another introduction that focuses more on the graph theory and conceptual ideas behind Git to help the reader understand what's happening as they use Git commands.

  • A practical git introduction is exactly what the title says it is. This is a well written guide with plenty of code snippets to get you up to speed with Git.

  • Git from the inside out demonstrates how Git's graph-based data structure produces certain behavior through example Git commands. This is a highly recommended read after you've grasped the basics and are looking to go deeper with Git.

Source control learning checklist

  1. Pick a version control system. Git is recommended because on the web there are a significant number of tutorials to help both new and advanced users.

  2. Learn basic use cases for version control such as committing changes, rolling back to earlier file versions and searching for when lines of code were modified during development history.

  3. Ensure your source code is backed up in a central repository. A central repository is critical not only if your local development version is corrupted but also for the deployment process.

  4. Integrate source control into your deployment process in three ways. First, pull the project source code from version control during deployments. Second, kick off deployments when code is modified by using webhooks or polling on the repository. Third, ensure you can roll back to a previous version if a code deployment goes wrong.

What do you want to learn about after source control?

I've built a Python web app, now how do I deploy it?

I want to learn more about app users via web analytics.

How do I log errors that occur in my application?

Sign up here to receive a monthly email with major updates to this site, tutorials and discount codes for Python books.


Matt Makai 2012-2017