{"id":66232,"date":"2022-08-05T09:02:18","date_gmt":"2022-08-05T09:02:18","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=66232"},"modified":"2022-08-05T09:02:18","modified_gmt":"2022-08-05T09:02:18","slug":"delete-the-local-reference-to-a-remote-branch-in-git","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=66232","title":{"rendered":"Delete the local reference to a remote branch in Git"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">Delete the local reference to a remote branch in Git<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/agantony\" class=\"username\">Agil Antony<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Fri, 08\/05\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-70134\" class=\"rate-widget-thumbs-up\" title=\"Register or Login to like.\">\n<div class=\"rate-thumbs-up-btn-up vote-pending\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<div class=\"rate-score\"><a href=\"https:\/\/opensource.com\/user\/register\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml\">Login<\/a> to like<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>After you merge a GitLab or GitHub pull request, you usually delete the topic branch in the remote repository to maintain repository hygiene. However, this action deletes the topic branch only in the remote repository. Your local Git repository also benefits from routine cleanup.<\/p>\n<p>To synchronize the information in your local repository with the remote repository, you can execute the <code>git prune<\/code> command to delete the local reference to a remote branch in your local repository.<\/p>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">More on Git<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/resources\/what-is-git?intcmp=7013a000002CxqLAAS\">What is Git?<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-git?intcmp=7013a000002CxqLAAS\">Git cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-markdown?intcmp=7013a000002CxqLAAS\">Markdown cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/git?intcmp=7013a000002CxqLAAS\">New Git articles<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<p>Follow these three simple steps:<\/p>\n<h2>1. Checkout the central branch of your repository (such as main or master)<\/h2>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">git checkout<\/span> <span class=\"sy0\">central_branch_name<span class=\"sy0\">&gt;<\/span><\/span><\/code><\/span><\/pre>\n<h2>2. List all the remote and local branches<\/h2>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">git branch<\/span> <span class=\"re5\">-a<\/span><\/code><\/span><\/pre>\n<p>Example output:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">\u00a0 <span class=\"nu0\">4.10<\/span>.z<br><span class=\"sy0\">*<\/span> master<br>\n\u00a0 remotes<span class=\"sy0\">\/<\/span>mydata<span class=\"sy0\">\/<\/span><span class=\"nu0\">4.9<\/span>-stage<br>\n\u00a0 remotes<span class=\"sy0\">\/<\/span>mydata<span class=\"sy0\">\/<\/span><span class=\"nu0\">4.9<\/span>.z<br>\n\u00a0 remotes<span class=\"sy0\">\/<\/span>mydata<span class=\"sy0\">\/<\/span>test-branch<\/div><\/div><\/pre>\n<p>In this example, <code>test-branch<\/code> is the name of the topic branch that you deleted in the remote repository.<\/p>\n<h2>3. Delete the local reference to the remote branch<\/h2>\n<p>First, list all the branches that you can delete or prune on your local repository:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">git remote<\/span> <span class=\"kw2\">prune<\/span> origin <span class=\"re5\">--dry-run<\/span><\/code><\/span><\/pre>\n<p>Example output:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">Pruning origin<br>\nURL: <span class=\"kw2\">git<\/span><span class=\"sy0\">@<\/span>example.com:myorg<span class=\"sy0\">\/<\/span>mydata-<span class=\"nu0\">4.10<\/span>.git<br><span class=\"sy0\">*<\/span> <span class=\"br0\">[<\/span>would <span class=\"kw2\">prune<\/span><span class=\"br0\">]<\/span> origin<span class=\"sy0\">\/<\/span>test-branch<\/div><\/div><\/pre>\n<p>Next, prune the local reference to the remote branch:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">git remote<\/span> <span class=\"kw2\">prune<\/span> origin<\/code><\/span><\/pre>\n<p>Example output:<\/p>\n<pre>\n<div class=\"geshifilter\"><div class=\"bash geshifilter-bash\">Pruning origin<br>\nURL: <span class=\"kw2\">git<\/span><span class=\"sy0\">@<\/span>example.com:myorg<span class=\"sy0\">\/<\/span>mydata-<span class=\"nu0\">4.10<\/span>.git<br><span class=\"sy0\">*<\/span> <span class=\"br0\">[<\/span>pruned<span class=\"br0\">]<\/span> origin<span class=\"sy0\">\/<\/span>test-branch<\/div><\/div><\/pre>\n<p>That&#8217;s it!<\/p>\n<h2>Maintaining your Git repository<\/h2>\n<p>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. Don&#8217;t slow yourself down by forcing yourself to sift through data you no longer need.<\/p>\n<p>Regularly deleting local references to remote branches is a good practice for maintaining a usable Git repository.<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>Follow a few simple steps to keep your Git repository tidy.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/08\/freesoftwareway_law3.png\" width=\"520\" height=\"292\" alt=\"A diagram of a branching process\" title=\"A diagram of a branching process\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>Opensource.com<\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/git\" hreflang=\"en\">Git<\/a><\/div>\n<\/p><\/div>\n<div class=\"hidden field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/08\/cc-by-sa-4-6.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delete the local reference to a remote branch in Git Agil Antony Fri, 08\/05\/2022 &#8211; 03:00 Register or Login to like Register or Login to like After you merge a GitLab or GitHub pull request, you usually delete the topic branch in the remote repository to maintain repository hygiene. However, this action deletes the topic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":66233,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-66232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/66232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66232"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/66232\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/66233"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}