Git Basics: How to create, move, delete, list Git branches?
Git is now a common tool in software development, for version controlling. In the last post, we described about " How to rename a Git b...- Article authored by Kunal Chowdhury on .
Git is now a common tool in software development, for version controlling. In the last post, we described about " How to rename a Git b...- Article authored by Kunal Chowdhury on .
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.
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:
$ git branch
$ 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>
$ 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)
$ git branch -d <branch-to-delete>
Delete a local branch (forcefully):
$ git branch -D <branch-to-delete>
$ 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!
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.