Table of Contents
1. What is Source Control?
Software companies usually have tens or even hundreds of developers working together on a product or products. They need to have an efficient way to merge their code together, as well as have the tools to do code reviews, make backups, and check past versions of code files. A Source ControlĀ (aka Version Control) solution gives us features for all of these.
Git and TFS are probably the most popular solutions currently in use, and some others include SVN and Mercurial. They each function somewhat differently, but share a lot of the same concepts. For our class we will be using Git.
2. Repositories
A Repository is basically like a single "Project". You might have multiple repositories for different projects, or a company might have multiple repositories for different software products.
A Git Repository is set up so that Git takes care of tracking changes over time, create branches to work on new features, automatically merge changes with other people, and more.
3. Commit log
Git keeps track of changes made by different developers over time. Each time we use the commit command, a "snapshot" of our changes are made. Once synced to the GitLab server, we can see a list of all commits in the history of the project.
4. Git blame
If we click on a commit, we can view a log of which lines of code were changed - red for "removed", + green for "added".
5. Continuous integration
The system architect can also set up scripts so that whenever new code is synced on the server, a build is run - this builds the project (and usually runs automated tests), and reports if the build/tests are successful or not.
This helps us know if a new feature we're working on breaks the build or makes other tests fail.
(You won't have to configure this.)
6. GitLab - Issues
GitLab also has an Issue Tracker, where we can create Issues (aka Tickets) to log tasks that need to be completed or bugs found in the code. We can associate our commits to an issue number # so that we can easily reference when and where a feature was added or a bug was fixed.
7. GitLab - Issue board
GitLab also has other project management features such as a "Issue Board" (often called a Kanban board) to more visually track what needs to get done.
8. Branches
When a developer begins working on a new feature the common practice is for them to create a new branch. This makes a clone of our main branch and allows the developer to add new code, without affecting main.
Generally, the main branch should only contain code that is complete and tested, so the developer works in their feature branch while developing a feature.
Once they're done with a feature, usually a peer will review their code, and the team lead will merge the feature branch with main.
9. Merge requests
Once a developer is done with creating a new feature on their own feature branch, then they create a Merge Request on GitLab. This will create a view where other developers can view all the commits/changes related to this feature, add comments, and approve the merge request if everything looks good.
10. Code reviews
Code reviews are a common part of software development. When a developer is done with a feature they will create a merge request for their branch. Other developers will read through the code commit looking for obvious issues, adding comments if anything is found.
If the merge request gets approved then the team lead merges the feature branch into the main branch.
11. Git vs. GitLab
- Git itself is a whole system that facilitates this organized software development.
- GitLab is a service that provides hosting for Git repositories. (GitHub is another common example.)
- Each developer installs the Git software to their computer, which allows them to communicate to the repository's server with basic action commands.