If you have a git branch at the remote origin and you want to completely delete this branch both from the local and the remote location, then you should follow the below git commands on the command line (or the terminal if using the Mac)
For demonstration, lets create a feature/local branch myproject/ticket-1
% git checkout -b "myproject/ticket-1"
Switched to a new branch 'myproject/ticket-1'
Now let us push this branch to origin (remote git server, which is GitHub in our case),
% git push git push -u origin myproject/ticket-1
...
remote:
To https://github.com/myuser/mynotes.git
* [new branch] myproject/ticket-1 -> myproject/ticket-1
branch 'myproject/ticket-1' set up to track 'origin/myproject/ticket-1'.
Git Delete Branch: Local
Options to delete Git Branch Locally
git branch -d local-branch-name
git branch -delete local-branch-name
git push origin -d -f local branch-name
git push origin --detete --force local branch-name
Example:
# git branch -d myproject/ticket-1
error: The branch 'myproject/ticket-1' is not fully merged.
If you are sure you want to delete it, run 'git branch -D myproject/ticket-1'.
% git branch --delete --force myproject/ticket-1
Deleted branch myproject/ticket-1 (was 601a63a).
Make use of the option -d (delete) and -f (force) options to delete the local branch if not fully merged. You can also use -D instead of -d -f to ignore checking merged status.
✋️ Note: If you are on the feature branch and try to delete it you will get an error "commit delete branch", make sure you are on main/master or some other branch when you execute this command.
Example:% git branch --delete --force myproject/ticket-1
error: Cannot delete branch 'myproject/ticket-1' checked out at '/myproj'

Example - Git Delete Local Branch
Git Delete Branch: Remote
To delete a git branch from the remote origin, you can push the branch with -d or --delete option,
Options to delete Git Branch from Remote (GitHub/BitBucket)
% git push origin --delete branch-name
% git push origin -d branch-name
% git push origin -d myproject/ticket-1
Username for 'https://github.com': mygithubuser
Password for 'https://mygithubuser@github.com':
To https://github.com/mygithubuser/myproj.git
- [deleted] myproject/ticket-1

Example: Git - Delete Remote Branch
Related Questions
- How to remove a Git Local Branch?
- How to remove a Git Remote Branch?
- Github - How to delete a branch?
Related Articles:
- GitHub Doc - Creating and deleting branches within your repository
- GitHub Docs - Deleting and restoring branches in a pull request
- Git Branch Documentation
Facing issues? Have Questions? Post them here! I am happy to answer!
- Fix [oh-my-zsh] Cant update: not a git repository
- [fix] fatal: pathspec index.html did not match any files error
- How to ignore files in git using .gitignore file
- Git Fix: fatal: refusing to merge unrelated histories Error
- Install GitHub Command Line Tool on Mac
- How to change directory in Git bash
- Get List of all local branches git command
- fix fatal: --local can only be used inside a git repository error
- [git] fatal: your current branch 'main' does not have any commits yet
- Git Revision Questions Before the Interview
- Change the default git branch name from master to main
- git command to remove/unstage files from staging area
- Remove git config at Local, Global or System Levels?
- [fix] fatal: this operation must be run in a work tree in git
- Clone a particular remote brach using git clone command
- How do I get a list of all branches in Git?
- How to check your installed version of Git
- Step-by-Step: How to delete a git branch from local as well as remote origin
- Git Commit - Author identity unknown, Please tell me who you are email
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- How to Rename a Git Local Branch Using the --move Option
- Perform an Empty Commit in Git without anything in Staging Area
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- GitHub: How to Search Code
- Rename git branch on Local and GitHub Remove using Command
- How to check your installed version of Git - Git
- Fetch only content-type using cURL Command - cURL
- How to Open TextEdit on Mac - MacOS
- How to get end of line (EOL) or new line character \r \n in Java - Java
- macOS Ventura XCode Command Line Tools Installation - MacOS
- Launch Notepad++ html document in any web browser - NotepadPlusPlus
- Ways to Convert Java Array to Stream - Java
- Sublime Add text at start and end of each line - Sublime