How To Rename, Delete Branch in a Remote Git Repository?

Delete Remote Git Branch

To delete a Remote Branch first you need to clone that project in your local machine. Then after the project is cloned you can delete a remote git repository by typing following command:

$ git push --delete <remote_name> <branch_name>

Remote branch for most of the project by default is origin.

Delete Local Git Branch

To delete the local branch you can use any of the following commands:

$ git branch -d branch_name
$ git branch -D branch_name

 -d is an alias for --delete, and -d only deletes the branch if it has already been fully merged in its upstream branch.  -D, is an alias for --delete --force, which deletes the branch “irrespective of its merged status.”

Rename Remote Git Branch

In order to rename a remote git branch, we have to first create a new branch on our local. Name of local branch should be the desired one. Then we should push it to the remote repository. Than after that delete the old remote branch. All these things can be done by typing following commands:

$ git branch new-branch-name origin/old-branch-name
$ git push origin --set-upstream new-branch-name
$ git push origin :old-branch-name