This study will discuss the method to prune remote branches in Git. So, go ahead and explore it!
How to Prune Remote Branches in Git?
Suppose you have a Git development project with many branches created in the Git remote repository and fetched into the local repo to perform different operations. However, after performing these operations, you want to delete them from our local repo. To do so, list all branches of the Git repository to check all branches that are available in our repository. Then, run the “$ git remote prune origin” command for the specified purpose.
Let’s go ahead to implement the discussed scenario!
Step 1: Move to Git Repository
Navigate to the Git local repository using the given-below command:
Step 2: List Git Branches
Next, list all the existing branches of the Git repository, including both remote and local branches:
Here, the list of all available branches is displayed, and we have highlighted the remote branches:
Step 3: Prune Remote Branches
Now, to prune the tracked remote branches, execute the “git remote prune” command with <origin>:
According to the below output, over remote branches are pruned successfully:
We have learned the easiest procedure to prune remote branches in Git.
Conclusion
To prune the remote branches in Git, first, go to Git local repository and execute the “$ git branch -a” command to list all branches of the Git repository. After that, utilize the “$ git remote prune origin” command to prune the remote tracked branches. In this study, we have demonstrated how to prune remote branches in Git.