GitHub

GitHub

What's GitHub?

GitHub (Links to an external site.) is an online repository hosting service and is the most commonly used of its kind in the software industry. While git is a command line tool, GitHub provides us with an online graphical user interface (GUI) to use for storing and working with our repositories.

Understanding the basic commands to work with git and subsequently publish your work to a remote repository is of the utmost importance for you as you enter the job force.

For more information on our GitHub setup in Labs, see our entry in the Labs Guides (Links to an external site.).

Branching

This is something you already know how to do. Using git checkout -b <your-branch-name> is how we create new branches to work off of.

In Labs, we require that all branches be broken off of the main branch in your repositories. This will allow for a clean development flow.

There are two types of branches you'll create during your time in Lambda School Labs, and we ask that you follow a specific naming convention for each flow:

  1. Feature branches: feature/description-description-of-the-feature

    • Example: If I needed to implement a login form for my app, my branch name would be feature/login-form

  2. Bug branches: bug/description-of-bug

    • Example: If I was fixing the login form button, my branch name would be bug/login-submit-handler

The reason for segmenting everything into these two simple branching flows is so that you don't have a messy git history—the chronological log of changes that were made to your project's code over time.

In the real world, you might see more complex and/or specific strategies, depending on how your team operates. Knowing this flow will help you be prepared for any strategy a team deems necessary to deploy.

Creating Pull Requests and Draft Pull Requests

Forking vs. Cloning

In order to submit your code for review and eventually merge your code into the main branch of your project's repository, you'll need to open a pull request.

This step is one you're familiar with at this point in your Lambda School journey. The main difference between what you've been doing in core instruction versus what we do here in Labs is that you won't fork your project's repositories—instead, you'll clone them, working within the same GitHub organization.

Forking is a natural choice for open source contributions to product repositories in GitHub organizations that you don't belong to. Here in Labs, you'll be part of the Lambda School Labs GitHub organization. You've been granted write access to the repos with which you'll be working.

Thus, in Labs, you'll never need to fork a repository—except perhaps at the very end of your project, when you can decide to fork your project repos to keep a copy of your work in that state after you leave Labs (note that if you don't do this, you'll lose access to the project code!).

Draft Pull Requests

A draft pull request (Links to an external site.) is a feature introduced by GitHub in early 2019 that lets you easily share and track a work in progress. As you go through the process of opening a pull request, you can designate it as a draft, which comes with many benefits.

Draft pull requests can't be merged, so you won't accidentally merge in changes that aren't ready. When you submit draft pull requests, you also won't spam any "code owners" (in Labs, your Release Manager!) with spurious notifications.

But opening a draft pull request will let you easily show your work and consolidate a conversation around it as it progresses. We highly recommend using draft pull requests in Labs to maximize visibility into your work and facilitate the number one factor in the success of a project: communication.

Further Reading

Rebasing

Throughout your career, you'll encounter a variety of merging strategies. We require you use a Git Rebase (Links to an external site.) strategy for your team's workflow in Labs.

How teams merge code is a hotly debated topic in the industry, but here in Lambda School Labs, we ask that you use a rebase strategy to keep your git commit history clean. Although there are other strategies for merging code across development teams, rebase is the dominantly accepted practice in the industry today.

Why Rebase?

On occasion, you'll find that you've been working on a feature branch and you need to merge in changes from the main branch. This could just be a final step before you push a series of commits to GitHub in order to create a pull request (PR). Or, maybe it's to update your branch from main after a day or so of work.

With rebasing, you approach this situation by finding the "common ancestor" of the main and feature branch, and then "replaying" the commits made since then to create a new base commit.

Sound complicated? Here's how it works:

How to Rebase

These steps are similar to what the "Rebase and Merge" action does on GitHub. (You should always use this if "Squash and Merge" isn't available.)

  1. Make sure all changes are committed to your feature branch.

  2. Update your local master branch:

    • > git checkout master

    • > git pull origin master

  3. Go back to your feature branch:

    • > git checkout feature-branch

  4. Now we can rebase the feature branch onto master:

    • > git rebase master

    • Result: First, rewinding head to replay your work on top of it... Applying: added staged command

  5. Your commits will now show in the git log after the commits merged from master.

For more information, see our entry on Git Rebase in the Labs Guides (Links to an external site.).

Further Reading

Merge Conflicts

What are Merge Conflicts?

Merge conflicts occur within a development team's workflow when two developers try and update the same line of code in the same file. When this happens, git will inform you that you have a merge conflict.

You need to resolve merge conflicts before pushing to your branch and rebasing your code into main.

When a merge conflict occurs, git will write some text directly into the file where the conflict exists. You'll need to:

  1. Go into that file and remove that inserted text

  2. Specify which lines of code you want to live in your branch

💡 Pro tip: VSCode (and other IDEs) have great merge conflict tools built in. We highly recommend you resolve any merge conflicts that arise with another developer present—preferably the developer whose code you're conflicting with!

Dealing With Merge Conflicts

Here's how to deal with merge conflicts in practice:

Further Reading

Reviewing Pull Requests

Here in Lambda School Labs, we firmly believe that clean code lives and dies by authoring and reviewing high-quality pull requests.

In Labs, the pull request is the final step between your development lifecycle and deployment. Since it's your final step to get your code pushed to production, it's of the utmost importance that you try your hardest to ensure that the quality of the code you'll be submitting is held to the highest standard possible.

Pull Request Requirements in Labs

We require that each pull request:

  • contains a brief, 2–5 minute video walkthrough presenting your work

  • is well documented and provides links to any supporting documents—like Trello cards, design artifacts, or further documentation to ensure everyone knows why the pull request was necessary.

  • has commits that are relevant to what has changed.

  • contains work relevant to the pull request description.

  • has been adequately reviewed by at least 2 peers and your release manager. Your release manager has final approval, and your code will not be merged into main unless your release manager has approved it.

  • contains maintainable code that has been formatted to your product specifications.

  • follows industry best practices.

Not only do pull requests highlight the code you write—they're the best mechanism for a hiring manager get a glimpse into how you work as an effective member of a dev team. Treat them as professionally as you'd like to be treated in the industry.

The Pull Request Rubric

Follow our rubric to help you practice authoring and reviewing proper pull requests. Throughout Labs, we'll hold regular Pull Request Critique sessions, where your engineering manager will breakdown the work you've done and how you've worked to make it clear to reviewers.

Pull Request Rubric

Pull Request Rubric

Last updated