Merging branches

Intermediate Git

George Boorman

Curriculum Manager, DataCamp

The purpose of branches

  • Each branch should have a particular purpose

    • Developing a new feature
    • Debugging an error
  • Once the task is complete, we incorporate the changes into production

    • Typically the main branch - "ground truth"
Intermediate Git

Source and destination

  • When merging two branches:

    • the last commits from each branch are called parent commits
    • source—the branch we want to merge from
    • destination—the branch we want to merge into
  • When merging ai-assistant into main:

    • ai-assistant = source
    • main = destination
Intermediate Git

Merging branches

  • Move to the destination branch:
git switch main
  • git merge source

  • From main, to merge ai-assistant into main:

git merge ai-assistant
  • From another branch: git merge source destination
git merge ai-assistant main
Intermediate Git

Git merge output

Output of the git merge command

Intermediate Git

Git merge output

git_merge_output with a highlight on the commit hashes

  • Parent commits
Intermediate Git

Git merge output

git_merge_output with a highlight on the type of merge

  • Linear commit history: branched off main to create ai-assistant
  • Fast-forward: point main to the last commit in the ai-assistant branch
Intermediate Git

Git merge output

git_merge_output with a highlight on the number of lines changed

Intermediate Git

Git merge output

git_merge_output with a highlight on the last line showing the name of the file that was created

Intermediate Git

Let's practice!

Intermediate Git

Preparing Video For Download...