Introduction to branches

Intermediate Git

George Boorman

Curriculum Manager, DataCamp

What we will cover

  • Branches

 

  • Remotes

 

  • Conflicts

Image of the Git logo

Intermediate Git

What you should know

  • How Git stores data
  • How to create repos
  • How to make commits
  • How to compare versions
  • How to revert versions

Foundations of Git

Intermediate Git

Branches

  • Branch = an individual version of a repo

  • Git uses branches to systematically track multiple versions of files

 

  • In each branch:
    • Some files might be the same
    • Others might be different
    • Some may not exist at all

Paralell universe

Intermediate Git

Why use branches?

Live system

DataCamp Courses page

  • Works as expected
  • Default branch = main

Feature development

DataCamp Courses page with the AI Assistant

  • Might encounter issues during development and testing
  • Doesn't affect the live system
Intermediate Git

Why use branches?

  • Multiple developers can work on a project simultaneously

 

  • Compare the state of a repo between branches

 

  • Combine contents, pushing new features to a live system

 

  • Each branch should have a specific purpose
Intermediate Git

Visualizing branches

Image of the main branch

Intermediate Git

Branching off

ai-assistant branch created from the main branch, and three commits made

Intermediate Git

Merging back into main

ai-assistant branch merged back into the main branch

Intermediate Git

Fixing a bug

bug-fix branch created from the main branch, with three commits made, before merging back into main

Intermediate Git

Identifying branches

  • Listing all branches
git branch
  main
* ai-assistant
  • * = current branch
Intermediate Git

Switching between branches

git switch main
Switched to branch 'main'
Intermediate Git

Creating a new branch

  • Create a new branch called speed-test
git branch speed-test
  • Move to the speed-test branch
git switch speed-test
Switched to branch 'speed-test'
  • Create a new branch called speed-test and switch to it
git switch -c speed-test
Switched to a new branch 'speed-test'
Intermediate Git

Terminology

  • Creating a new branch = "branching off"

  • Creating speed-test from main = "branching off main"

Intermediate Git

Let's practice!

Intermediate Git

Preparing Video For Download...