What is Branching?

What is Branching?

Branching is what happens when you want to work on multiple features at the same time. You wouldn’t want to end up with a master branch that has Feature 1 half done and Feature 2 half done. Furthermore, we would separate the code base into “snapshots” (branches) and work on and commit to them separately. As soon as we are ready, we might merge this branch back into the master branch and push it to the remote server.

When developers are working on a feature or bug they’ll often create a branch of their code they can make separate commits to. Then when they’re done they can merge this branch back into their main master branch.

branching

 

Creating a branch

/> git branch <branch_name>

We can switch branches using the git checkout <branch> command. You can also use -b to do both the things together( create a branch and checkout ):

/> git checkout -b new_branch

https://www.testingdocs.com/create-a-git-branch/

What is a pull request?

A pull request allows the project owner or code reviewer to look through your changes and make comments before deciding to merge in the change. It’s a really great feature that is used all the time for remote workers and open-source projects.

https://www.testingdocs.com/create-a-pull-request/

 

Pull Request

Git merge:

We might want to merge the changes from the branch into the master branch. Something like below, when you are on the master branch. Telling Git to merge the <branch_name>

/> git merge <branch_name>

Merge Conflicts can occur when changes are made to a file at the same time. When merge conflicts, we just need to decide which code to keep. There are tools to help to resolve merge conflicts.

https://www.testingdocs.com/resolving-merge-conflicts-on-github/

Delete a branch:

We can use the below command to delete a branch. For example to clean bug_fix branch :

/> git branch -d <branch name>

/> git branch -d bug_fix