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
# 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'
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://email@example.com': To https://github.com/mygithubuser/myproj.git - [deleted] myproject/ticket-1
- How to remove a Git Local Branch?
- How to remove a Git Remote Branch?
- Github - How to delete a branch?
- GitHub Doc - Creating and deleting branches within your repository
- GitHub Docs - Deleting and restoring branches in a pull request
- Git Branch Documentation
Have Questions? Post them here!
- Git: Delete Branch Locally and Remotely at Origin
- How to change directory in Git bash
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- Get List of all local branches git command
- How to check your installed version of Git
- 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.
- git command to remove/unstage files from staging area
- fix fatal: --local can only be used inside a git repository error
- Github: How to Invite Collaborators
- How to Install Git on Windows
- Get the file location of git config values
- Change the default diff or commit editor for git
- GitHub: How to Search Code
- [fix] zsh: command not found: git
- Setup Git + Visual Studio Code Tutorial
- Fix [oh-my-zsh] Can't update: not a git repository
- [fix] fatal: this operation must be run in a work tree in git
- Git: Step-by-Step - How to Push Local Brach to GitHub
- How to ignore files in git using .gitignore file
- Rename git branch on Local and GitHub Remove using Command
- Change the default git branch name from master to main
- Github: fatal: Authentication failed Support for password was removed on August 13, 2021
- Git Remove Untracked Files using Command
- git fatal: Authentication failed error [fix]
- Git Rename master branch make to main using Command
- How to create StackOverflow error in java - Java
- Maven Eclipse (M2e) No archetypes currently available - Java
- Parse XML file in Java using DOM Parser - Java
- Android AlertDialog with Yes No and Cancel Button - Android
- [Solution] Android Studio does not displays Toolbar in Layout Design - Android-Studio
- Fixing Android unknown error 961 while downloading app - Android
- How to add Date and Time to Windows Notepad File - NotepadPlusPlus
- Docker Commit Command with Examples - Docker