How to delete a branch in git: 1. To delete the local branch, use [git branch --delete dev] to execute; 2. To delete the remote branch, use the [git push origin --delete branch] command; 3. Delete tracking branch.
The operating environment of this article: Windows 7 system, git2.26.2 version, Dell G3 computer.
Recommended (free): Git tutorial
How to delete a branch in git:
1. Delete local branch
When deleting a branch, we will use git branch --delete dev
to execute. Sometimes we will also use the abbreviation git branch -d dev
instead. During use, we found that there is also a way of writing git branch -D dev
. What are the differences between them?
-d is --Delete abbreviation. When using --delete to delete a branch, the branch must be completely merged with its upstream branch (to understand the upstream branch, you can click to view the link). If there is no upstream branch, it must be completely merged with HEAD
-D is the abbreviation of --delete --force. This way you can delete the branch without checking the merge status
--force The abbreviation -f is to reset the current branch to the initial point (startpoint). If --force is not used, the git branch cannot modify an existing branch.
2. Delete the remote branch
Commandgit push origin --delete branch
, this command will also delete the tracking branch
3. Delete the tracking branch
You can delete the tracking branch through the command git branch --delete --remotes <remote>/<branch></branch></remote>
, This operation does not actually delete the remote branch, but the relationship between the deleted local branch and the remote branch, that is, tracking branch
as above, through the command line git push origin --delete branch
will To delete remote branches and tracking branches, you do not need to delete the tracking branches separately. However, if you delete the remote branch through the web page, the tracking branch will not be deleted.
After git version 1.6.6, you can use git fetch origin --prune
or its abbreviation git fetch origin -p
to individually delete tracking branches
The above is the detailed content of How to delete a branch in git. For more information, please follow other related articles on the PHP Chinese website!