0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
You might be primarily familiar with using Git in a single-user environment, pushing updates through a linear workflow. For example:
# working off of the "main" branch locally
git add .
git commit -m "undo Lane's giant mistake"
git push origin main
This works quite well for single developer side projects, but it doesn't work well when you're working within a team setting. What happens when a teammate makes changes to the same function you're working on and you both push directly to the main
branch? What happens if you want a teammate to review your code before it's merged? What happens if you want to work on multiple features at once?
Branches solve these problems.
A branch is (basically) a copy of your codebase. However, it's a special kind of copy that makes merging new code changes from one branch to another simple and easy.
So far, you may have been only working on the main
branch, but you can create as many branches as you want, and they're a great way to keep changes that are unrelated to each other isolated and contained.
In many teams, the main
branch reflects the state of the codebase that's running in production. This means that the main
branch should always be stable and ready to deploy. If you want to:
Then you should create a new branch to add those changes to. This allows you to work on those changes independently without affecting the main
branch.
git branch
. You'll see a list of branches, with an asterisk next to the branch you're currently on:* main
addtests
. I like to name my branches after the change I'm about to make, and in this case, we're about to add tests.git switch -c addtests
git push origin addtests
You can check on GitHub to make sure the branch exists.
Paste the URL of your GitHub repo into the box and run the GitHub checks.
Paste the link to your public GitHub repo:
Checks that will be run:
Login to view solution