Programming For Non-Techies is a weekly feature for non-techies to learn to program every Friday. This week’s lesson will focus on a necessary programming tool, source control. If you’re a non-techie and you want to learn to program, or maybe you want a job in tech and need a better understanding of programming, these posts will help you!
If you’re new here, I strongly suggest looking at the previous programming posts since they build on each other.
What is source control?
Source control, or version control, is a tool used to keep track of different versions of code and software. First of all, this gives us a place, called a repository, to save our source code and related files for a program. Once we have our code in source control then any revisions made to files are tracked. It keeps track of what changed and who changed it. Sometimes a change is made that doesn’t work as expected, source control lets you roll back, or revert, a change. This is useful when working on a project by yourself, but it’s necessary when working with other developers.
Since source control keeps tracks of revisions to files, all developers working in a code base can review previous changes and see the full history of changes made to a file. This helps with troubleshooting issues or with catching up if you’ve been away on vacation. If you are away for any period of time, the code you’re working with is probably out of date. Source control takes care of that too since you can always grab the latest and greatest versions.
How does source control work?
There are many very different ways that source control systems are implemented. One basic way allows developers to check in and check out files. When a file is checked out, then it’s locked and nobody else can change it until it’s checked back in or released. This prevents developers from making conflicting changes to a file. It also slows down work since only one developer can work on a given file at a time. Other source control systems improved on this and figured out ways to allow multiple developers to work on a file at the same time. This is usually done by an automated merging of changes. If the merge is complicated then developers usually have to manually merge changes.
Git a widely used distributed source control repository. It’s called distributed because each user has a complete copy of the repository. This is in contrast to a centralized single repository.
I’ve put all the previous coding examples into GitHub which is a Git repository hosting service. Go to https://github.com/techfornontechies/programming to see the repository. If you click on the src directory, you can view the sample code. From there you can click on each file to view it. After you have had a chance to look around, go back to https://github.com/techfornontechies/programming.
Click on the green button that says Clone or download. Click the button to the right of the address to copy the address. Now open Eclipse. In the Package Explorer right click and select Import. If you don’t see this, just click File and then select import. There should be an option for Git. Expand that option and then choose Projects from Git. Now choose Clone URI and click Next. Enter the information as it is below. Click Next two times and then make sure the Directory is where you want the code downloaded. Click Finish.
This downloads the code from GitHub and creates a local repository on your computer. Anytime you want to grab the latest example files, right click on the project in Package Explorer, select Team and then select Pull. I’ll use GitHub for all the code in future examples so please make sure you set this up. Let me know if you have any problems in the comments.