Working with branches

Introduction to GitHub Concepts

George Boorman

Curriculum Manager, DataCamp

Branches

  • Enable concurrent work on different parts of a project
  • Help reduce the risk of conflicting file versions

diagram of three branches: main, la liga, and premier league

Introduction to GitHub Concepts

Main branch

current branch highlighted in the code section of the repo

Introduction to GitHub Concepts

How many branches?

number of branches highlighted in the code section of the repo

Introduction to GitHub Concepts

Creating a new branch

branch icon highlighted in repo's code section

Introduction to GitHub Concepts

Creating a new branch

list of branches, showing only main. New branch button to the right in green

Introduction to GitHub Concepts

Creating a new branch

adding the branch name la liga and creating a branch

Introduction to GitHub Concepts

Creating a new branch

updated branch list including la liga

Introduction to GitHub Concepts

Adding a file

Line plot of home vs away goals in la liga; Code section of la liga branch with home vs away goals plot included

Introduction to GitHub Concepts

Listing branches

Two branches highlighted in the repo's Code section

Introduction to GitHub Concepts

Switching branches

dropdown menu listing active branches main and la_liga

Introduction to GitHub Concepts

Switching branches

choosing main from the branch dropdown menu

Introduction to GitHub Concepts

Comparing branches

Code section of main branch without the second la liga plot

Introduction to GitHub Concepts

Working with branches

hands pulling different sections of a pie chart

Introduction to GitHub Concepts

Branch protection rules

  • Rules for specific branches
    • Require a pull request before merging
    • Require that pull requests are approved before merging
    • Restrict who can delete a protected branch

padlock

1 Image credit: https://unsplash.com/@bluzninja
Introduction to GitHub Concepts

Branch protection rules

Settings section of repo highlighted

Introduction to GitHub Concepts

Branch protection rules

branches section of Settings tab

Introduction to GitHub Concepts

Branch protection rules

branches in the settings tab, showing Default branch as main and a section for adding Branch protection rules

Introduction to GitHub Concepts

Adding rules

Naming branch name pattern as protect main

Introduction to GitHub Concepts

Require a pull request

Video clicking Require a pull request before merging

Introduction to GitHub Concepts

Saving the rule

Click create to save the rule

Introduction to GitHub Concepts

Let's practice!

Introduction to GitHub Concepts

Preparing Video For Download...