Skip to content
  • Home
  • Contact Us
  • About Us
  • Privacy Policy
  • DMCA
  • Linkedin
  • Pinterest
  • Facebook
thecscience

TheCScience

TheCScience is a blog that publishes daily tutorials and guides on engineering subjects and everything that related to computer science and technology

  • Home
  • Human values
  • Microprocessor
  • Digital communication
  • Networking
  • Toggle search form

How to Delete a git branch remote/local branch

Posted on October 9, 2022 By YASH PAL No Comments on How to Delete a git branch remote/local branch

In this article, we are going to learn about how to delete a git branch Locally and Remotely.


Table of Contents

  • How to Delete a remote branch
  • How to Delete a branch locally

How to Delete a remote branch

To delete a branch on the origin remote repository, you can use Git version 1.5.0 and newer.

git push origin : <branchName>

you can delete a remote branch using

git push origin --delete <branchName>

To delete a local remote-tracking branch:

git branch --delete --remotes <remote>/<branch>
git branch -dr <remote>/<branch> # Shorter
git fetch <remote> --prune # Delete multiple obsolete tracking branches
git fetch <remote> -p # Shorter

To delete a branch locally. Note that this will not delete the branch if it has any unmerged changes:

git branch -d <branchName>

To delete a branch, even if it has unmerged changes:

git branch -D <branchName>

How to Delete a branch locally

$ git branch -d dev

Deletes the branch named dev if its changes are merged with another branch and will not be lost. If the dev branch

does contain changes that have not yet been merged that would be lost, git branch -d will fail:

$ git branch -d dev

error: The branch ‘dev’ is not fully merged.

If you are sure you want to delete it, run ‘git branch -D dev’.

Per the warning message, you can force delete the branch (and lose any unmerged changes in that branch) by

using the -D flag:

$ git branch -D dev
coding problems, git

Post navigation

Previous Post: How to use for loop inside a list in python
Next Post: Codechef XOR Equal problem solution

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pick Your Subject
Human Values

Copyright © 2023 TheCScience.

Powered by PressBook Grid Blogs theme