{"id":108844,"date":"2023-10-02T07:00:00","date_gmt":"2023-10-02T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=108844"},"modified":"2023-10-01T20:43:37","modified_gmt":"2023-10-02T03:43:37","slug":"20231002-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20231002-00\/?p=108844","title":{"rendered":"How do I manually update a remote tracking branch, say, to undo a fetch?"},"content":{"rendered":"<p>One of my colleagues who writes git tools wanted to know how to force a local repo&#8217;s remote tracking branch into a stale state. Doing so would allow testing of various edge cases.<\/p>\n<pre>$ git fetch origin\r\nremote: Enumerating objects: 15, done.\r\nremote: Counting objects: 100% (15\/15), done.\r\nremote: Total 15 (delta 0), reused 6 (delta 0), pack-reused 0\r\nFrom http:\/\/contoso.com\/sample\r\n   844de02..01781ca  main       -&gt; origin\/main\r\n<\/pre>\n<p>How can we &#8220;unfetch&#8221; the <code>origin\/main<\/code> branch so the local repo thinks that the remote is still on <code>844de02<\/code>?<\/p>\n<p>The magic command is <a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Git-Internals-Git-References\"> <code>git update-ref<\/code><\/a>. This command lets you set the commit for any branch or tag.<\/p>\n<pre>$ git update-ref refs\/remotes\/origin\/main 844de02\r\n<\/pre>\n<p>You can also use it to undo the creation of a branch via a fetch.<\/p>\n<pre>$ git fetch origin\r\nremote: Enumerating objects: 22, done.\r\nremote: Counting objects: 100% (22\/22), done.\r\nremote: Total 22 (delta 0), reused 9 (delta 0), pack-reused 0\r\nFrom http:\/\/contoso.com\/sample\r\n * [new branch]      dev        -&gt; origin\/dev\r\n<\/pre>\n<p>You can delete the remote tracking branch by saying<\/p>\n<pre>$ git update-ref -d refs\/remotes\/origin\/dev\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Updating refs to point to whatever you like.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-108844","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>Updating refs to point to whatever you like.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=108844"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/108844\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=108844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=108844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=108844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}