This post is pretty old, and might contain outdated advice or links. We’re keeping it online, but recommend that you check newer posts to see if there’s a better approach.All blog posts
We greatly extended our knowledge of the version control system by following Thoughtram's two-day workshop on the powers of Git.
Why Should You Use Version Control?
Version control is a system that records all of the changes to a file over time. It allows you to compare two versions of a file and revert files back to a previous version. Using version control also means that you can easily recover files if you messed up. These features make it an indispensable tool for developers.
At De Voorhoede, we use Git in all of our projects. Before the workshop, we were already familiar with most of Git's concepts: we knew how to fetch and merge changes, how to create a branch, etc.. However, we wanted to take our knowledge to the next level and be as productive as possible in our daily workflow. Thoughtram's workshop was a great opportunity for the Voorhoede developers to become real Git Masters.
The Git Master Class
The Git Master Class was supposed to be hosted at De Voorhoede office, but due to a little fire in the building a few weeks ago, the venue was changed to the Razmataz restaurant. At Razmataz, De Voorhoede and the other attendees were welcomed by Thoughtram's trainers, Christoph and Pascal.
During the introduction it became clear that most attendees joined the workshop for the same reason: we all know and use Git, but we wanted to truly grasp the underlying concepts and advance our knowledge about the version control system.
On day one, Christoph and Pascal walked us through the basics of version control and Git: What is a distributed version control system? What is the anatomy of a Git commit? What are branches and tags? These are a few of the questions that were answered in the morning. In the afternoon, we discussed more advanced topics including merge strategies and reset modes.
During the second day, we dove in a little deeper and learned more about rebasing, working with remotes and how to cherry pick commits.
What Did We Learn?
A few of the most valuable lessons we learned are about Git branches and rebasing.
Git branches are part of our everyday development workflow. We create a new branch when we start working on a new feature or want to fix a bug. By creating a branch we make sure that we keep the code separate from the main code base. But what exactly is a branch? Even though we already used branches every day, we didn't know about the underlying implementation yet. To really understand the way Git handles branches, Christoph and Pascal first explained the way Git stores its data.
Git doesn't store data as a series of differences, but instead as a series of snapshots. When you make a commit, Git stores a commit object that contains a pointer to the snapshot of the content you staged. In Git, a branch is simply a movable pointer to a commit. When you create a new branch, all Git needs to do is to creates a new pointer - it doesn't change the repository in any other way.
To integrate committed changes from one branch into another branch we can use two techniques: merging and rebasing. At De Voorhoede, we commonly use the merge approach. However, we discovered that rebasing has some important benefits:
- Rebasing keeps your commit history clean, because there are no unnecessary merge commits.
- If there's a conflict, the solution is not hidden in the merge commit, but in the actual commit.
Branches and rebasing are a few of the key features of the Git version control system. During the workshop we have learned some clever tricks as well.
During everyday development, a small mistake is easily made. You can forget to stage a file or format your commit message the wrong way. The
git commit --amend command is a convenient way to fix those little mistakes. It lets you combine staged changes with the previous commit instead of committing it as an entirely new snapshot, effectively modifying the previous commit.
During the workshop, Christoph and Pascal showed us how to set up aliases and shortcuts for git commands. Having aliases for commands that you use a lot makes your workflow a lot easier and faster. If you want to learn some useful Git aliases, have a look at dotfiles.github.io.
We had two fun and informative days. With the help of Thoughtram we were able to greatly extend our knowledge of Git. In the future, we will be able to work even more efficiently and productively.
More pictures of the workshop can be found at Thoughtram's Facebook page.