Contents...
Git branch in git give us a lots of flexibility in our workflow. Suppose you want add some feature in your website so here what can we do we will create a branch and start working on it. Basically branches in git are simple pointer to create a specific commit. Git branch allow you to work easier to divide up your work in logically. Once you finish your work on branch now let’s merge it to master branch.
In this tutorial we will lear how to create git branch in git and and switch branch, checkout branch etc.
If you want to learn more about git you can follow my this Git Tutorial page.
Create Git Branch in Git
Here I am going to create a new branch named “dev”.
$ git branch dev
Or use this command instead of using single command we can use this below command to create and switch the branch with one single command.
$ git checkout -b dev
Branch dev create.
Switch Branch
Let’s check out to newly create branch. Run this below command:
$ git checkout dev
Now we are ready to commit our changes in this created branch.
List All Branches in Git
Execute this below command to list all the branches in git:
$ git branch * dev prod stage
Suppose your team member create a new branch and push to the remote repository. Here if you want to fetch that all branch run this below command.
$ git fetch --all
Once you switch the branch run git checkout command.
$ git checkout other_branch
Delete Git Branches
Now let’s delete branches
Delete local branch, run these two command to delete local branch:
$ git branch -d dev $ git branch -D dev
Delete remote git branch, run this below command to delete remote branch.
$ git push origin --delete dev
FAQs
What is a git branch in Git?
Basically branches in git are simple pointer to create a specific commit. Git branch allow you to work easier to divide up your work in logically.
How can I list all my Git branches?
You can list all your git branches in git repository using “git branch” command.
How can I rename my Git branch?
Simply run “git branch -n old_branch new_branch” command to to rename your git branch.
How can I push to a brach?
First, create and checkout out your new branch using “git checkout -b branch_name” command.
Second, now push the newly created branch to the remote repository using “Git Push -u origin branch_name” command.
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment