Git & Git branching tutorial ๐Ÿ”—

You should know!

You should already have a good understanding of how this works from the previous chapters Git Vs GitHub. This chapter focuses on Git.


Git branch --list

The git brach command show all braches list

git branch --list

Git branch

The git brach command show braches

git branch

List Remote Branches

To display all remote branches, execute the โ€œgit branchโ€ command:

git branch -r

In the above-mentioned command, the โ€œ-rโ€ indicates the remote branches. As you can see, currently, we have three branches in the remote repository


Fetch all branchs

we have used the โ€œโ€“allโ€ flag which will fetch all metadata of branches.

git fetch --all

pull --all

shows that all remote branches are successfully pulled

git pull --all

Create Git branch using checkout

create a new branch off main using git branch new_branch

git checkout -b branch-name

Switched to new branch 'branch-name'

Using checkout How To Switch Branch on Git

git checkout master git checkout existing_branch

Create Git branch using switch

create a new branch off main using git branch new_branch

git switch -c branch-name

Using Switch How To Switch Branch on Git

git switch master git switch existing_branch

Git Delete Branch

Git Delete Branch using -D

git branch -D branch-name

or

Using --delete

git branch --delete branch-name

View commit history

The commit history can be viewed in different ways by using the git log command. A local repository named bash has been used in this tutorial to test the commands used in this tutorial

git log

If You Want

A great way to learn from our GitHub Repository.