Tips For Programming in a Team
5
minute read time
Teamwork makes the dream work... efficient and organized teamwork does, anyways.
If your teamwork isn’t up to snuff, it can create more problems than you could ever imagine. With that being said, getting your development team in sync isn’t as daunting as it sounds. In fact, most of the resources I now use daily were brand new to me when I started working at Atypic. Unlike my last position, where I only ever worked with the other developers if we really needed help or a second pair of eyes, here at Atypic we frequently have multiple developers working on different tasks within the same project, sometimes at the same time. It was such a foreign concept to me. I had no idea how to keep up with what others were doing or if my changes would affect their code and vice-versa. Thankfully, my team was more than happy to share their knowledge with me and help get me on board with their processes.
I want to share two resources that I learned from my peers that made programming in a team easier than I could ever imagine.
Git & Rebase Command
First off, let’s talk about Git. I’ll be honest, Git scares the heck out of me. There’s so many commands and it’s not that hard to completely mess up your project if you don’t know what you’re doing. Luckily, you don’t need to memorize that many commands to be able to program effectively, in a team or by yourself. Everyone knows push, pull, checkout, and merge, but I want to talk about my new favorite Git command, rebase. The concept of rebasing is simple: you basically just catch up one branch to another. For example, let’s say you have a master branch for your live site and a feature branch for your dev site. As normal, you make your updates to the feature branch and merge them into master whenever they’re ready to be taken live. But, what happens when a hotfix is needed immediately and your feature branch isn’t ready to go live yet? You could just make the fix right on the master branch, but now that fix won’t appear on your dev site. You could just make the fix on both branches, but that’s redundant, time consuming, and basically asking for merge conflicts to happen. That’s where rebasing comes in.
Our development team has found that creating feature branches for every update, merging them into a develop branch for testing on a development site, and then merging into the master branch for deploying to the live site is the best way to keep our repositories nice and clean while being able to work on multiple updates in the same project. Each step of the process rebases our code with the upstream, so we know that our code will never be out of sync with other team members’ updates. And, if anything weird happens, we usually hop on a Slack call and rebase the branch together so we know what updates belong where. For more detailed information, check out the official documentation for the rebase command.
Visual Studio Code Live Share Extension
Now that we know how to rebase our branches so that the repository is kept nice and clean, let’s take a look at another aspect of being in a development team and pair programming. When we’re in the office, pair programming is as simple as walking over to another team member’s desk and getting started. Unfortunately, since working from home, that’s no longer possible. However, thanks to Visual Studio Code’s Live Share extension, we can pair program from home just as easily as we can in the office. All you need to do is download Visual Studio Code, install the Live Share extension, sign in with a Github or Microsoft account, and you’re ready to go. Starting up a Live Share session automatically copies an invite link to your clipboard, so after your programming partner follows the above instructions, they just need to open the invite link and they’re in! You can set permissions, share servers and terminals, and there’s even a handy “pin” button that allows you to follow where your partner is in the code in real time. It also automatically appends a notice to your next commit message saying that you collaborated on this update and displays your partner’s email address. Microsoft has a more in-depth guide for installation and usage specifics that I recommend reading into.
As a developer, it’s imperative that my code is clean, working, and well organized. There’s no telling who or when someone is going to be looking at it, making updates to it, or using it as a reference for another project. Learning how to rebase in Git and using Live Share to pair program on difficult tasks have significantly enhanced my ability to be a more effective programmer and team member.
What Is Rebasing?
Rebasing is an incredibly useful Git command that "catches up" a side branch with a main branch while still keeping all the updates made to the side branch.
Basically, the side branch becomes a copy of the main branch and then all the changes that weren't on the main branch are added back in.
The act of rebasing:
1. Checks the commits of both branches
2. Saves any commits that are present in the current branch but not in the upstream branch to a temporary area
3. Resets the current branch to the upstream branch
4. Applies those set aside commits to the updated current branch
For example, let’s say that your master branch has commits A, B, and C, your feature branch has D, E, and F, and the hotfix adds commit G. First, we would want to merge hotfix onto master, so master has A, B, C, and G. Then all we have to do is rebase feature with master, so now feature has commits A, B, C, G, D, E, F. If there ends up being merge conflicts when you’re rebasing, Git will take you step by step through each commit, let you resolve the conflict and then continue rebasing with git rebase --continue, or just skip the conflicting commit with git rebase --skip. Pretty simple, right?