How to delete a branch in git: 1. Use the "git branch --delete dev" command to delete the local branch; 2. Use the "git push origin --delete branch" command to delete the remote branch; 3. Use The "git branch --delete --remotes" command deletes tracking branches.
The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.
1. Delete local branch
When deleting a branch, we will use
git branch --delete dev
to execute. Sometimes it is replaced by the abbreviation
git branch -d dev
. During use, we found that there is also a way to write git branch -D dev. What is the difference between them?
-d is the abbreviation of --delete. When using --delete to delete a branch, the branch must be completely merged with its upstream branch (to learn about upstream branches, you can click to view the link). If there is no upstream branch, it must be merged with HEAD Complete merge
-D is the abbreviation of --delete --force. This way you can delete the branch without checking the merge status
--force, abbreviated as -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
Command git push origin --delete branch, this command will also delete the tracking branch
3. Delete the tracking branch
Through the command git branch --delete --remotes
is as above. Using the command line git push origin --delete branch will delete the remote branch and the tracking branch. There is no need to delete the tracking branch separately, but 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 delete the tracking branch individually through git fetch origin --prune or its abbreviation git fetch origin -p
Recommended learning: "Git Tutorial"
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!