Follow us on X (Twitter)  Like us on Facebook  Connect with us on LinkedIn  Subscribe to our YouTube Channel  Subscribe to our WhatsApp Group

Git is now a common tool in software development, for version controlling. In the last post, we described about "How to rename a Git branch?". Today we are going to learn more about Git branches and it's commands.

 

Continue reading to know how to create/rename/move/delete/list Git branches. Also, don't forget to check other posts on Git Basics/Git Cheat sheets.

 

GIT Branch Commands (www.kunal-chowdhury.com)

 

If you are working on Git Bash commands, you will regularly need to execute the basic commands. Today in this blog post, I am going to share more commands related to Git Branch and to keep them always handy with you. I hope, you will like these:

 

List all local branches:

$ git branch

 

List all remote branches:

$ git branch -r

 

List all existing branches with the latest commit comment:

$ git branch -av

 

Create a new local branch based on current HEAD:

$ git branch <new-branch-name>

 

Create a new tracking branch based on remote:

$ git checkout -t <remote-branch-name>

 

Switch your HEAD to a branch:

$ git checkout <branch-name>

 

Move or rename a local branch:

$ git branch -m <old-branch-name> <new-branch-name>

 

Move or rename a local branch (forcefully):

$ git branch -M <old-branch-name> <new-branch-name>
                                              (... more detailed on this topic)

 

Delete a local branch:

$ git branch -d <branch-to-delete>

 

Delete a local branch (forcefully):

$ git branch -D <branch-to-delete>

 

Delete a remote branch:

$ git branch -d <branch-to-delete>

$ git push origin :<branch-to-delete>

 

Was this post useful? If you came to this page by searching online about git basics, please have a look into my other blog posts. Subscribe to the RSS feed or the email newsletter to keep yourself updated. If you have any queries, you can either ping me on Twitter or drop a line below in the comments section. Have a great day!

 

 

Have a question? Or, a comment? Let's Discuss it below...

dhgate

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.