Setting up a Python Development Environment on OSX – Part 2 – Source Control

By , August 10, 2011

This is part 2 of a series on setting up a great Python development environment on OSX. Part 1 can be found here, Part 3 can be found here and Part 4 can be found here. This part is even simpler and focuses on getting Git installed and operational using GitHub to manage source code. The tasks are:

1. Intall Git
2. Configure Git & SSH to use your GitHub repository
3. Install the Github Mac client to manage your repositories and check-ins

Installing Git
The easiest way to install Git is via the installer package downloaded from http://www.git-scm.com. At the time of writing there is not a package specifically marked for Lion but the Snow Leopard package seems to work perfectly. When the package is complete a simple “git version” command will confirm that the client is functioning and return the installed version.

Git

Configure Git & SSH to use your GitHub repository
Assuming you already have a GitHub account (they are free but you need to pay to upgrade your account if you want private repositories) you will now need to configure SSH to connect to Github and configure some settings that Git will use. The GitHub instructions are superb and I couldn’t do anything to improve them so navigate over to the http://help.github.com/mac-set-up-git/ and complete the tasks, followed by the instructions to setup a repository (or repo) on http://help.github.com/create-a-repo/.

Github

When this is complete you can now created a repository to store your code, have a local client to check out the code base with and manage any revisions as well synchronize your local computer and the online repository.

Install the Github Mac client to manage your repositories and check-ins
While minimalist development (like minimalist running) is popular (text editors instead of IDE’s and command lines instead of GUI tools) most of the time you will be committing code to your local Git repository and pushing it to the master repository on GitHub. For this I personally find that a client makes life easier until you get to the advanced Git tasks like re-basing and merging branches of code in which the command-line rules. I have tried many Git client like Git-X, GitBox and SourceTree App but was delegated when I discovered last week that GitHub have released their own client (free). If you are just using Github then its a great simple UI for the common tasks and won’t get in the way of your command line for advanced operations. You can download it at http://mac.github.com/.

Macgit. When installed you simply enter your Github user name and password and the client shows you the repositories you have access to want to clone locally to work on. When you make changes to your local repository they will all show up in the UI so you can then commit them and push to the master repository online.

While this tutorial is far from a tutorial on using Git I recommend getting the O’Reilly Version Control with Git book or a good Git tutorial . I will cover how to setup Git to ignore key IDE configuration files when we cover installing Pycharm it is worth noting that some files in your local repository should remain local (config files with passwords as an example). The settings section under each repository allows you to enter content that will be ignored. This is simply a UI for the .gitnore file that your local repository uses but makes like a little easier.

Gitignore

You should now be able to create and manage repositories online (including forking others code in Github to explore). To prove it why not fork this https://github.com/curphey/python-students, clone it, add some sample code and send me a pull request ?

Next up configuring VirtualEnv to create and manage unique local setups for each project!

Share on TwitterSubmit to reddit

Panorama Theme by Themocracy