![]() Regularly deleting local references to remote branches is a good practice for maintaining a usable Git repository. Don't slow yourself down by forcing yourself to sift through data you no longer need. Keeping your Git repository tidy may not seem urgent at first, but the more a repository grows, the more important it becomes to prune unnecessary data. That's it! Maintaining your Git repository Next, prune the local reference to the remote branch: $ git remote prune origin To delete a remote branch, the command is: git push origin -delete branch It looks like someone forgot the -delete in one of the earlier answers. replacing the origin with the name of your remote. Delete the local reference to the remote branch.įirst, list all the branches that you can delete or prune on your local repository: $ git remote prune origin -dry-run git branch -all git remote prune origin git branch -all. In this example, test-branch is the name of the topic branch that you deleted in the remote repository.Ä£. So, to delete the remote branch AND locally-stored remote-tracking branch in one command, just use git push origin -delete .Checkout the central branch of your repository (such as main or master). NOTE: A colon (:) before the branch name has the same effect as the -d or delete option of git push. That's because it has syntax highlighting for everything â making it easier to work with Git. So, running the git branch -d command would only remove the branch locally.Īnd if you have issues working with Git, I suggest you switch your terminal to Git bash. Thatâs because youâve pushed the branch already. If you check GitHub again, it wonât be there:Ä«ear in mind that to completely remove a Git branch from your project, you need to use the git push origin command. ![]() You can see the remote branch, test-branch1, is not listed anymore. To verify that the remote branch has been deleted, run git branch -a again. So the syntax representing the command for removing a remote branch looks like this: git push origin -d branch-name.įor instance, to remove the test-branch1 branch, I will run git push origin âd test-branch1: To completely remove a remote branch, you need to use the git push origin command with a -d flag, then specify the name of the remote branch. But if you run git branch -a, the branch will still be listed.Īnd if you check GitHub, the branch will still be there: If you try to delete a remote branch with the same command used for deleting a local branch, you will get a message that the branch has been deleted. If you type in the command correctly, you will get a response that the branch has been deleted. To delete a local branch, run git branch -d branch-name. Then you may need to deleted local merged branch by hand with git branch -d .Branch deletion through the command line If you prefer to work from the CLI, you can delete GitHub branches that way, too. In this situation, test-branch2 is a branch Iâm yet to push, so itâs a local branch. After merging a branch Im able to delete the branch on remote. To delete a branch, click the trashcan icon next to its name. This is a feature I've seen only in Git bash. If you run git branch -a in particular, it will make the remote branches distinct. Run git branch or git branch -a to see the branches youâve created for your project. ![]() But it's okay if you use another terminal. Iâll use Git bash in this article because it makes working with Git easier than any other terminal. But firstly, letâs look at how to delete a local branch. In this article, I will show you how to delete a remote branch in Git. When you're working with Git, you might want to delete remote branches pushed to a platform like GitHub for various reasons.
0 Comments
Leave a Reply. |