Working with branches

Introduzione ai concetti di GitHub

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

Introduzione ai concetti di GitHub

Main branch

current branch highlighted in the code section of the repo

Introduzione ai concetti di GitHub

How many branches?

number of branches highlighted in the code section of the repo

Introduzione ai concetti di GitHub

Creating a new branch

branch icon highlighted in repo's code section

Introduzione ai concetti di GitHub

Creating a new branch

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

Introduzione ai concetti di GitHub

Creating a new branch

adding the branch name la liga and creating a branch

Introduzione ai concetti di GitHub

Creating a new branch

updated branch list including la liga

Introduzione ai concetti di GitHub

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

Introduzione ai concetti di GitHub

Listing branches

Two branches highlighted in the repo's Code section

Introduzione ai concetti di GitHub

Switching branches

dropdown menu listing active branches main and la_liga

Introduzione ai concetti di GitHub

Switching branches

choosing main from the branch dropdown menu

Introduzione ai concetti di GitHub

Comparing branches

Code section of main branch without the second la liga plot

Introduzione ai concetti di GitHub

Working with branches

hands pulling different sections of a pie chart

Introduzione ai concetti di GitHub

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
Introduzione ai concetti di GitHub

Branch protection rules

Settings section of repo highlighted

Introduzione ai concetti di GitHub

Branch protection rules

branches section of Settings tab

Introduzione ai concetti di GitHub

Branch protection rules

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

Introduzione ai concetti di GitHub

Adding rules

Naming branch name pattern as protect main

Introduzione ai concetti di GitHub

Require a pull request

Video clicking Require a pull request before merging

Introduzione ai concetti di GitHub

Saving the rule

Click create to save the rule

Introduzione ai concetti di GitHub

Let's practice!

Introduzione ai concetti di GitHub

Preparing Video For Download...