Debakar Roy

Day 8: Branching and merging in Git

1 min read

Branching and merging let developers work on multiple features or bug fixes simultaneously without disturbing the main codebase. Git tracks each branch’s changes, so collaboration stays organized.

Resources I referred to:

Git branches are ideal when working on new features or bug fixes that are not yet ready for the main codebase. To create a new branch:

git checkout -b new-feature

This creates a branch named new-feature where you can make changes freely. You can create as many branches as your project needs.

Once the changes are ready, merge them back into the main branch:

# Add all your changes
git add .

# Commit all of your changes
git commit -m "Commit message"

# Checkout the branch where you want to merge the changes
git checkout main

# Merge the changes from the feature branch
git merge new-feature

If there are merge conflicts, Git will prompt you to resolve them.

After merging, delete the feature branch:

git branch -d new-feature

Your changes are now part of the main branch, and the temporary branch is gone.