Add delete snippets

This commit is contained in:
Isabelle Viktoria Maciohsek
2021-04-08 19:42:01 +03:00
committed by Chalarangelo
parent 09872076b1
commit 3ce861522c
4 changed files with 75 additions and 1 deletions

View File

@ -5,7 +5,7 @@ tags: repository,branch,beginner
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
git branch -d <branch>

View 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
```

View 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
```

View 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
```