For Your Guidance – Technology

Git branch is an isolated set of changes within the repository. We can create N number branches and we can move changes from one branch to another branch.

Eg: if we want to implement multiple features at a time, but all changes should be isolated. In that case, we can create different branches for each feature. And finally, we can merge the required feature branch to the main/default branch.

Create a local branch and checkout

git checkout -b <branch name>

Git checkout is used to change the context from one branch to another branch. If we add -b, it will try to create a new branch and change the context to the new branch.

Delete branch

git branch -d <branch name>

-d option needs to be provided along with the branch name which we want to delete

List branches

git branch

This is used to list the branches which are already present in the local repository. I won’t show the branches that are created in the remote repo but didn’t download to the local branch

List branches including remote

git branch -a

By default, the git branch displays only branches that are already downloaded to the local repo. We need to append “-a” to fetch the remote branch info and display both local and remote branches.

5/5
Tags: Branching / GIT / SCM
Categories: DevOps / GIT

Latest Posts