Add delete snippets
This commit is contained in:
committed by
Chalarangelo
parent
09872076b1
commit
3ce861522c
@ -5,7 +5,7 @@ tags: repository,branch,beginner
|
|||||||
|
|
||||||
Deletes a local branch.
|
Deletes a local branch.
|
||||||
|
|
||||||
- Use `git branch -d <branch>` to delete the branch with the specified branch name.
|
- Use `git branch -d <branch>` to delete the specified local `<branch>`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
git branch -d <branch>
|
git branch -d <branch>
|
||||||
|
|||||||
28
snippets/delete-detached-branches.md
Normal file
28
snippets/delete-detached-branches.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
title: Delete detached branches
|
||||||
|
tags: repository,branch,intermediate
|
||||||
|
---
|
||||||
|
|
||||||
|
Deletes all detached branches.
|
||||||
|
|
||||||
|
- Use `git fetch --all --prune` to garbage collect any detached branches.
|
||||||
|
- This is especially useful if the remote repository is set to automatically delete merged branches.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git fetch --all --prune
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git checkout master
|
||||||
|
git branch
|
||||||
|
# master
|
||||||
|
# patch-1
|
||||||
|
# patch-2
|
||||||
|
|
||||||
|
# Assuming `patch-1` is detached
|
||||||
|
git fetch --all --prune
|
||||||
|
|
||||||
|
git branch
|
||||||
|
# master
|
||||||
|
# patch-2
|
||||||
|
```
|
||||||
29
snippets/delete-merged-branches.md
Normal file
29
snippets/delete-merged-branches.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
title: Delete merged branches
|
||||||
|
tags: repository,branch,advanced
|
||||||
|
---
|
||||||
|
|
||||||
|
Deletes all local merged branches.
|
||||||
|
|
||||||
|
- Use `git branch --merged <branch>` to list all branches merged into `<branch>`.
|
||||||
|
- Use the pipe operator (`|`) to pipe the output and `grep -v "(^\*|<branch>)"` to exclude the current and the target `<branch>`.
|
||||||
|
- Use the pipe operator (`|`) to pipe the output and `xargs git branch -d` to delete all of the found branches.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git branch --merged <branch> | grep -v "(^\*|<branch>)" | xargs git branch -d
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git checkout master
|
||||||
|
git branch
|
||||||
|
# master
|
||||||
|
# patch-1
|
||||||
|
# patch-2
|
||||||
|
|
||||||
|
# Assuming `patch-1` is merged into master
|
||||||
|
git branch --merged master | grep -v "(^\*|master)" | xargs git branch -d
|
||||||
|
|
||||||
|
git branch
|
||||||
|
# master
|
||||||
|
# patch-2
|
||||||
|
```
|
||||||
17
snippets/delete-remote-branch.md
Normal file
17
snippets/delete-remote-branch.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: Delete a remote branch
|
||||||
|
tags: repository,branch,intermediate
|
||||||
|
---
|
||||||
|
|
||||||
|
Deletes a remote branch.
|
||||||
|
|
||||||
|
- Use `git push -d <remote> <branch>` to delete the specified remote `<branch>` on the given `<remote>`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git push -d <remote> <branch>
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git checkout master
|
||||||
|
git push -d origin patch-1 # Deletes the `patch-1` remote branch
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user