YouTip LogoYouTip

Git Branching and Merging

Introduction

Branching allows you to develop features, fix bugs, and experiment in isolation. Merging brings changes back together. This workflow is central to team collaboration.

Branch Operations

# List branches
git branch

# Create a new branch
git branch feature-login

# Switch to a branch
git checkout feature-login

# Create and switch (shortcut)
git checkout -b feature-login

# Modern alternative
git switch -c feature-login

# Delete a branch
git branch -d feature-login

Merging

# Switch to target branch
git checkout main

# Merge feature branch
git merge feature-login

# Merge with no fast-forward (preserves branch history)
git merge --no-ff feature-login

Handling Merge Conflicts

# When conflicts occur, edit the file manually
# Conflicts look like:
<<<<<<>>>>>> feature-branch

# After resolving:
git add resolved-file.txt
git commit -m "Resolve merge conflict"

Summary

Branching enables parallel development. Use checkout -b for new branches, merge to combine, and resolve conflicts manually when they arise.

← Git RemoteGit Tutorial - Getting Started β†’