Intern
What is a branch in Git?
sobes.tech AI
Answer from AI
A branch in Git is a pointer to a specific commit. Essentially, it is an independent line of development. Creating a branch creates a new pointer to the current commit, allowing changes to be made without affecting other branches.
Main characteristics and purposes:
- Isolation of changes: Branches allow working on different features or bug fixes in parallel, isolating changes from each other.
- Merging: Changes from one branch can be integrated into another (usually into the main branch, such as
mainormaster) using the merge operation. - Creation and deletion: A branch is easy to create and delete after work on it is completed and its changes are integrated.
Example of creating and switching branches:
# Creating a new branch "feature/my-feature"
git branch feature/my-feature
# Switching to the newly created branch
git checkout feature/my-feature
# Alternative way to create and switch
git checkout -b another-feature
Example of merging a branch:
# Switching to the branch where changes need to be integrated (e.g., main)
git checkout main
# Merging the "feature/my-feature" branch into the current branch
git merge feature/my-feature