Home > Development Tools > git > body text

How to delete a branch in git

WBOY
Release: 2022-06-24 14:29:00
Original
83813 people have browsed it

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.

How to delete a branch in git

The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.

How to delete a branch in git

1. Delete local branch

When deleting a branch, we will use

git branch --delete dev
Copy after login

to execute. Sometimes it is replaced by the abbreviation

git branch -d dev
Copy after login

. 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 /, you can delete the tracking branch. This operation does not actually delete the remote branch, but deletes the local branch and remote branch. The relationship between the branches, that is, the tracking branch

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!

Related labels:
git
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template