![]() Git branch -D only deletes local branches, and not the remote versions in the repo. Always test the regular expression to select your branches git branch | grep foo before passing them to git branch -D. Use caution when executing this command, as it will be difficult to recover branches deleted by accident. ![]() We’ve avoided writing out each branch name one-by-one! Danger ⚠️ This has the same result as writing git branch -D fix/ticket-123 task/ticket-123 task/ticket-123-v2 which deletes each of these branches. Using backticks, we pass the branch names to the git branch -D command. ![]() Choose TortoiseGit from the context menu. Now we have our list of filtered branches, we can delete them all. When using SourceTree, you can delete branches one at a time by right-clicking on the branch and selecting 'Delete.' However, if you want to delete multiple branches simultaneously, you can follow these steps using the TortoiseGit UI: Right-click on the project folder. Grep can use complex regular expressions to search, but here all we need is a simple string pattern, ticket-123. Prevent Errors when sending local branches to remote (you won’t push to the remote old branches from months ago you. Grep then filters the branches by the pattern provided. This command lists all the branches and pipes the output to grep. Using grep, we can select only those branches, since the names have a common pattern: $ git branch | grep ticket-123 They should be deleted to keep our environment tidy. Ticket-123 was completed weeks ago and the branches associated with it are stale. Imagine if you type git branch at your terminal and you see: $ git branch git branch -D `git branch | grep your-regex` But if you have several branch names that match a regular expression, then you can delete them all at once. However, it can be tedious to delete many branches by typing each name individually. But if you’re like me, you don’t do this very regularly! When I type git branch into the terminal I’m confronted with dozens of dead branches.ĭelete local branches by typing git branch -D branch-name in your terminal. Branches quickly expire and are no longer needed, so it’s a good idea to delete them. After working for a while on a project, it’s likely that you’ll have a lot of branches checked out locally.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |