To delete a Git branch locally and remotely follow any one of the below commands with the appropriate Git version currently installed in your machine.
Delete Remote Branch
--delete option in
git push, you can delete a remote branch. In the below code we are considering the remote name as origin (because it is used in most cases).
git push origin --delete <branch> # Git version 1.7.0 or newer git push origin -d <branch> # Alias in the Shorter version (Git 1.7.0 or newer) git push origin :<branch> # older Git versions below 1.7.0
Example : If you want to remove your codefix branch from the server, run the below command:
git push origin --delete codefix
Delete Local Branch
To delete the Local Git Branch, use any one of the below command which bests suites for your need.
git branch -d <branch_name> git branch -D <branch_name>
-D works as follows:
-doption is an alias for
--delete, which deletes the branch only if it has previously been fully merged in its upstream branch.
-Dflag is an alias for
--force, which deletes the branch regardless of its merged status.
- If you attempt to delete the currently chosen branch, you will receive an error.