Git Branching
Branching is a fundamental concept in Git that allows developers to create separate lines of development within a repository. This documentation provides an overview of branching using a practical example.
Example Scenario
Consider a scenario where a team is working on a project with the following branch history:
Let's break down the Git manipulations
Two initial commits are made on the main branch, representing the starting point of the project.
A new branch named "185-staff-refactor-chips" is created from the latest commit on the main branch.
Switch to the newly created branch.
Two commits are made on the "185-staff-refactor-chips" branch to implement specific changes.
Switch back to the main branch.
After completing work on the feature branch, developers merge the changes from the "185-staff-refactor-chips" branch into the main branch.
After merging the feature branch, developers continue making commits directly on the main branch to further develop the project.
Branching Commands
Creating a Branch
To create a new branch, you can use the git branch command followed by the desired branch name. For example:
Switching Branches
To switch between branches, you can use the git checkout command followed by the branch name. For example:
Viewing Branches
To view a list of branches in your repository, you can use the git branch command without any additional arguments. For example:
Merging Branches
To merge changes from one branch into another, you can use the git merge command. For example, to merge changes from the 185-staff-refactor-chips branch into the main branch:
Deleting Branches
To delete a branch, you can use the git branch -d command followed by the branch name. For example:
Conclusion
Branching is a powerful feature in Git that enables efficient collaboration and version control in software development projects. By understanding how to create, switch, merge, and delete branches, developers can effectively manage their codebase and work on features or fixes independently.