Creating branches
Creating a branch in Git means establishing a separate line of development that diverges from the main codebase. When you create a branch, Git essentially creates a pointer to a specific commit, typically the commit you were on when you created the branch.
Creating a new branch does not change the repository; it simply points out the commit.
For example, if we create a branch called issue1
using the git branch command, the repository will remain the same, but we have added a new pointer to the current commit.
The illustration below shows what happens when we create this branch.
Here’s a breakdown of what happens when you create a branch:
- Pointer creation: Git creates a new pointer (or reference) to a specific commit in the repository. This commit is often referred to as the "head" of the branch.
- Independent development: The new branch initially contains the exact same code and commit history as the branch it was created from. This allows you to start making changes and commits independently from other branches.
- Commit history: As you make new commits on the new branch, Git updates the branch pointer to track the latest commit. Each commit on the branch builds upon the previous one, forming a chronological history of changes specific to that branch.
- Branch naming: Branches are typically named to reflect the feature being worked on, the issue being addressed, or any other relevant identifier. Naming conventions often help in identifying the purpose of each branch.