Cheat Sheet
Table of Contents
Review Branching
When should we create a new branch?
Branches are used to diverge from the main code base. They are useful because they create a copy of existing code without modifying the existing code. Think of it as your very own sandbox where you can create anything new.
Therefore, a new branch should be created for any new change to any of the files in the project. This includes but is not limited to creating a new feature in the repo and/or fixing a bug in the repo.
When do merge conflicts occur?
Merge conflicts occur when we have code that could possibly overwrite code that was already there. They are bound to happen if multiple people are working on the same file.
Things to avoid
The main branch should always have working code so as a best practice...
Don't work off of the
mainbranch.Avoid merging code that hasn't been tested or reviewed into the
mainbranch.
Creating Branches
Each team member should own their own branch and work exclusively on that branch.
Or, create a branch and switch to it in one command:
Then see all branches:
You should then see: (the * indicates the current branch)
TIP: Always check to make sure that you are NOT working in the
mainbranch
To switch back and forth between main and your branch, run:
Commit Changes
When you're ready to save your current changes, create a local commit.
In your feature branch, run:
Merge before you push
While you have been working on your code, your teammates may have pushed changes.
First, switch to the main branch and pull the changes:
Then, switch back to your feature branch and merge the changes from main into your branch.
You may need to resolve merge conflicts at this point. To resolve a conflict, delete the <<<<<<< HEAD, =======, and >>>>>>> main markers and keep the code that you want.

Finally, make a new commit to finish resolving these conflicts:
Push and make a PR
Once you have merged main into your branch, go ahead and git push.
If it is your first time pushing from this branch, you will be told to use the
--set-upstreamflag.
Go to Github.com and open up your repository.
Then, click on the Pull Requests tab to create a new pull request to merge your branch into
main.Ask your teammates to review your code and then merge!
If you want to continue working on your branch, do NOT delete the branch.
Your teammates can then follow the steps listed in merge before you push to update their local repositories.
Last updated