{"id":12122,"date":"2022-05-16T10:00:00","date_gmt":"2022-05-16T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=12122"},"modified":"2022-05-13T17:49:02","modified_gmt":"2022-05-13T08:49:02","slug":"deleting-a-git-branch-locally-and-remotely","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/12122","title":{"rendered":"Deleting a Git branch locally and remotely"},"content":{"rendered":"\n<p>You may have accidentally created a local branch or a remote branch on your local machine or remote host, respectively. In other cases, you may simply want to delete the local or remote branch.<\/p>\n\n\n\n<h3>Delete the local branch<\/h3>\n\n\n\n<p>To delete a local Git branch, you need to specify the &#8211;delete or -d flag in your git branch command (the latter is just an alias for &#8211;delete).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git branch --delete local-branch<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Or you can also use like this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git branch -d local-branch<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>As for force deleting , you can use like this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git branch -D my-local-branch-name<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3>Delete a Remote Branch<\/h3>\n\n\n\n<p>You can delete a remote branch using as below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$git push origin --delete remote-branch<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Now, once the remote branch is removed from the remote host, you need to make sure that the other machines are also in sync. The branch has been removed from both the local machine and the remote host, but other machines may still have the old tracking branch. This can be listed by running <code>git branch -a<\/code>.<\/p>\n\n\n\n<p>To ensure that all machines are in-sync, you need to run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$git fetch --all --prune<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Yuuma<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12122\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/12122\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Deleting a Git branch locally and remotely\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12122\" data-text=\"Deleting a Git branch locally and remotely\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12122\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12122\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>You may have accidentally created a local branch or a remote branch on your local machine or remote host, resp [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12122"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=12122"}],"version-history":[{"count":2,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12122\/revisions"}],"predecessor-version":[{"id":12125,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12122\/revisions\/12125"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=12122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=12122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=12122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}