{"id":46391,"date":"2025-08-16T08:28:05","date_gmt":"2025-08-16T08:28:05","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/?p=46391"},"modified":"2025-08-16T08:28:05","modified_gmt":"2025-08-16T08:28:05","slug":"delete-github-repository-history","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/delete-github-repository-history\/","title":{"rendered":"Delete GitHub repository history"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Deleting the .git folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Checkout\/create orphan branch (this branch won\u2019t show in git branch command):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git checkout --orphan latest_branch<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add all the files to the newly created branch:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git add -A<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Commit the changes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git commit -am \"commit message\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Delete main (default) branch (this step is permanent):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git branch -D main<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Rename the current branch to main:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git branch -m main<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, all changes are completed on your local repository, and force update your remote repository:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">git push -f origin main<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"ps-this-will-not-keep-your-old-commit-history-around-now-you-should-only-see-your-new-commit-in-the-history-of-your-git-repository\">PS: This will not keep your old commit history around. Now you should only see your new commit in the history of your git repository.<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>Deleting the .git folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following: Checkout\/create orphan branch (this branch won\u2019t show in git branch command): Add all the files to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":46588,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Delete GitHub repository history - Code DPlugins","description":"Deleting the .git folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is"},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[105],"tags":[],"dpc_library":[],"class_list":["post-46391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-github"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=46391"}],"version-history":[{"count":0,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/46391\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46588"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=46391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=46391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=46391"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=46391"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}