![]() ![]() įor example: git push origin -delete fix/authentication Here's the command to delete a branch remotely: git push -delete. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The -d option will delete the branch only if it has already been pushed and merged with the remote branch. For example: git checkout mainįor example: git branch -d fix/authentication Git will not let you delete the branch you are currently on so you must make sure to checkout a branch that you are NOT deleting. Once work is completed on a feature, it is often recommended to delete the branch. Repos often have a main branch for the main codebase and developers create other branches to work on different features. They are a great way to work on different features and fixes while isolating the new code from the main codebase. It is common for a Git repo to have different branches. You'll learn how to delete a Git brach locally and remotely in this article. While this is an overly simplistic explanation of what is happening behind the scenes, it hopefully provides an idea of how commands and their outputs can be spliced together using pipes.In most cases, it is simple to delete a Git branch. In our flow: git branch ( STDOUT ) - > ( STDIN ) grep -iE 'FIX|FEAT' ( STDOUT ) - > ( STDIN ) xargs git branch -D ( STDOUT ) The STDOUT is the result of running a command and is passed in as STDIN to the next command. ![]() In our case, the condensed data flow looks something like this: git branch - > grep -iE 'FIX|FEAT' - > xargs git branch -DĮach side of our pipe has a “standard input” (STDIN) and “standard output” (STDOUT). Many resources exist on pipes and their usages, but it may help to visualize usage in the context of deleting this branch deletion command. We can now see that instead of a single command that takes advantage of pipes, we had to type 6 different commands, each of which has a standard output of its own – making it tougher to keep track of what was deleted, and what still needs to be cleaned up. ĭeleted branch fix/RS-56 ( was 5a82faa ). ĭeleted branch feat/RS-96 ( was 6c114fb ). ĭeleted branch FIX/RS-456 ( was ea9973f ). If we typed the deletions manually for each branch, instead of using the full command, it would look something like this: $ git branch -D FEAT/RS-123ĭeleted branch FEAT/RS-123 ( was 1b39b22 ). Using the pipe operator, we passed the output of git branch into the grep. Our grep command highlighted the matching branches and each matched phrase. Now, let’s try to find all of the branches that we want to delete: $ git branch | grep -iE 'FIX|FEAT' Running git branch returns all of the existing local branches. To visualize this, let’s run each of these commands individually: $ git branch
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |