Owneat Technical Guide main Help

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:

main185-staff-refactor-chips0-3f40ef41-58f772a🚨 Fix lint on final page.🐛 Fix customer table transfer.5-5bdb2926-a1480d0

Let's break down the Git manipulations

  1. Two initial commits are made on the main branch, representing the starting point of the project.

  2. A new branch named "185-staff-refactor-chips" is created from the latest commit on the main branch.

  3. Switch to the newly created branch.

  4. Two commits are made on the "185-staff-refactor-chips" branch to implement specific changes.

  5. Switch back to the main branch.

  6. After completing work on the feature branch, developers merge the changes from the "185-staff-refactor-chips" branch into the main branch.

  7. 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:

git branch "185-staff-refactor-chips"

Switching Branches

To switch between branches, you can use the git checkout command followed by the branch name. For example:

git checkout "185-staff-refactor-chips"

Viewing Branches

To view a list of branches in your repository, you can use the git branch command without any additional arguments. For example:

git branch

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:

git checkout main git merge "185-staff-refactor-chips"

Deleting Branches

To delete a branch, you can use the git branch -d command followed by the branch name. For example:

git branch -d "185-staff-refactor-chips"

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.

Last modified: 21 May 2024