Lecture # 10 - Concept of Branches

Lecture # 10 - Concept of Branches

Creating new branches. Deleting branches. Switching to different branches. Merging branches

Branches:

In Git, branches are essentially pointers to a specific commit in the repository's history. They allow you to work on different parts of your project simultaneously without interfering with each other.

View Branches:

To view the branches git branch is used. If there is a * with the branch name, this means that branch is the current one.

Creating a Branch:

To create a new branch git branch [branch-name] is used.

Switching Branches:

There are two commands to switch between branches:

  • git checkout [branch-name] :

  • git switch [branch-name] :

Creating and Switching Branches in One Step:

There are two commands to create and switch branches in one step

  • git checkout -b [branch-name] :

  • git switch -c [branch-name] :

Merging Branches:

Once you've completed work on a branch and want to incorporate those changes into another branch (often the main branch), you can merge the changes using the git merge [branch-name] command.

Deleting Branches:

To delete a branch git branch -d [branch-name] is used.