![delete branch git delete branch git](https://zellwk.com/images/2018/git-branch/delete-1.png)
In the following example, we delete the branch named testing. The branch which will be deleted is added as a parameter like below. The long form of the -d option is -delete. The -d option is used for delete operation. We are going to execute the following command. The default way to delete a local branch in git is using the git branch -d. In this case, let’s say that we want to delete the file “file1” contained in our repository. –prune-empty : avoid having empty commits in the repository with zero files, this option will prune commits automatically.“git rm” command : the command to be executed on all branches, revisions and commits matching in the history, in this case it will remove the file from the repository and ignore files that don’t match.–index-filter : option used in order to rewrite the index, exactly what we want in the case of a file deletion.–force : quite self-explanatory, it forces the filter-branch to start even if it may not want to (given the documentation because it can contain temporary directories).$ git filter-branch -force -index-filter -prune-empty "git rm -cached -ignore-unmatch " HEADĪs the command is quite complex, let’s have a breakdown of all the options used :
![delete branch git delete branch git](https://linuxhint.com/wp-content/uploads/2019/06/1-25-1024x479.png)
In this case, the Git command to be executed is the “git rm” command we described earlier. In order to delete file from Git history, you have to use the “git filter-branch” command and specify the command to be executed on all the branches of your Git history.įinally, you want to specify the revision to execute the changes from : we are going to choose HEAD (as a reminder, HEAD is the last commit of your repository). If your branch is named feature for example, to. First, list all the branches that you can delete or prune on your local repository: git remote prune origin -dry-run. The -d option stands for delete and it can be used whenever the branch you want to clean up is completely merged with your upstream branch. Delete the local reference to the remote branch. It may be the case for example if you committed a file that contains passwords or some sensitive information, that you want to remove. The easiest way to delete local Git branches is to use the git branch command with the -d option. In some cases, you want to delete files from your entire Git history. Commit your gitignore file and you should be good to go! Delete Files From Git History