I had someone ask me recently about deleting branches. While I had known how to delete a local branch, I had to look up how to delete a remote one. Documenting these both will hopefully help me remember this.
Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.
Deleting Branches
Most parameters have something do to with the action, and most people might guess a –d is used to delete a branch in Git. The actual syntax for a branch named “Feature123” is:
git branch –d Feature123
You can also use a –D, though be aware that –D is the same as –d with the –force option. The –d actually aliases to –delete, so you have three options:
- -d
- –delete
- -D (this will run –-force)
To delete a remote branch, you can use (with v1.7+)
git push origin –-delete Feature123
where origin is the remote name and Feature123 is the branch. This is better than the old syntax, and you ought to keep your git up to date.
You can see this working for one of my branches below:
Git docs for branch have more details.
Use this to clean up branches if your changes are merged and you don’t need to send in any more PRs for this branch.
SQL New Blogger
This is a simple thing, but one that I don’t do often, so I wrote this as much to document it for myself as to put this out there as a piece of knowledge. If someone reads this post and asks the question in an interview, it’s likely an easy one for me to give.
You can do this, help showcase your career knowledge and control the interview. This piece took me about 8 minutes to write. You could do your own version of this topic.