{"id":187,"date":"2021-03-03T18:05:42","date_gmt":"2021-03-03T18:05:42","guid":{"rendered":"https:\/\/andrejacobs.org\/?p=187"},"modified":"2022-04-11T20:24:24","modified_gmt":"2022-04-11T20:24:24","slug":"deleting-unwanted-forks-from-github","status":"publish","type":"post","link":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/","title":{"rendered":"Deleting unwanted forks from GitHub"},"content":{"rendered":"\n

Photo by Yancy Min<\/a> on Unsplash<\/a><\/p>\n\n\n\n

At some point in my life I thought it would be a good idea to start forking git repos in GitHub instead of just starring them. I guess it started with a fear the repos might not exist in some point in the future and that I would like to have a copy for reference. But really how many times do I ever go back to stored bookmarks, or saved copies of things. Guess I am a digital hoarder.<\/p>\n\n\n\n

Deleting forks you no longer want from GitHub is a real PITA.<\/p>\n\n\n\n

Enter this repo https:\/\/github.com\/yangshun\/delete-github-forks<\/a> to save the day!<\/p>\n\n\n\n

Setup a GitHub token to be used by delete-github-forks<\/code><\/h3>\n\n\n\n

Go to https:\/\/github.com\/settings\/tokens\/new<\/a> and create a new token. I used delete-github-forks as the Note field.<\/p>\n\n\n\n

Set the public_repo and delete_repo permissions for the token.<\/p>\n\n\n\n

Generate the token and then make sure you copy the token and store it securely<\/strong> (I use 1Password).<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Configure delete-github-forks<\/h3>\n\n\n\n

Clone the repo.<\/p>\n\n\n\n

$ cd [some directory you want the repo to be stored]\n$ git clone https:\/\/github.com\/yangshun\/delete-github-forks.git\n$ cd delete-github-forks<\/code><\/pre>\n\n\n\n

Install dependencies.<\/p>\n\n\n\n

$ npm install<\/code><\/pre>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Configure the credentials to be used against GitHub.<\/p>\n\n\n\n

$ cp src\/config.json.example src\/config.json\n$ vim src\/config.json   [I like TextMate, so normally I am lazy and just use the mate command]<\/code><\/pre>\n\n\n\n

Specify your GitHub username and the token you generated earlier.<\/p>\n\n\n\n

Fetch the list of forks<\/h2>\n\n\n\n
$ cd src\n$ node fetch-repos.js\n\n...\nForked repos found: 50\n^^ Geez!<\/code><\/pre>\n\n\n\n

This creates a file called repos.json<\/code> and you need to remove all the forks that you actually want to keep.<\/p>\n\n\n\n

It is worth reiterating from the repo’s documentation:<\/p>\n\n\n\n

The repositories that remain inside repos.json<\/code> will be deleted on the next command. It is an irreversible operation. Use with great caution!.<\/strong><\/p><\/blockquote>\n\n\n\n

See the last section on how I did a quick verification on each fork to see if I wanted to keep it or not.<\/p>\n\n\n\n

Deleting the unwanted forks<\/h2>\n\n\n\n

See the warning above. Make sure you only keep the forks in repos.json<\/code> that you actually want to delete.<\/p>\n\n\n\n

Delete the forks.<\/p>\n\n\n\n

$ node delete-repos.js<\/code><\/pre>\n\n\n\n

Amazing in less than 2 seconds this deleted 68 forks I was no longer needing!<\/p>\n\n\n\n

Miscellaneous<\/h2>\n\n\n\n

I wanted to visit the GitHub page for each of the forks. So I thought I would open all the tabs in bulk from the command line<\/p>\n\n\n\n

$ sed -e 's|\"andrejacobs|open \"https:\/\/github.com\/andrejacobs|' repos.json | sed -e 's\/\",\/\"\/' | awk '{$1=$1};1' | bash<\/code><\/pre>\n\n\n\n

Breakdown<\/strong><\/p>\n\n\n\n

Replace “andrejacobs with: open “https:\/\/github.com\/andrejacobs<\/p>\n\n\n\n

sed -e 's|\"andrejacobs|open \"https:\/\/github.com\/andrejacobs|'<\/code><\/pre>\n\n\n\n

Replace “, with: “<\/p>\n\n\n\n

sed -e 's\/\",\/\"\/'<\/code><\/pre>\n\n\n\n

Trim whitespace<\/p>\n\n\n\n

awk '{$1=$1};1'<\/code><\/pre>\n\n\n\n

This is by far not the most optimized or best way but it did open 50+ tabs in my browser.<\/p>\n\n\n\n

The process was pretty simple. I check what the fork is about and even visit the repo it was forked from to see if it still exists etc. and then made an informed decision if I wanted to keep my fork or not. Also now was a good time to start starring repos I cared about and NOT fork them.<\/p>\n","protected":false},"excerpt":{"rendered":"

Photo by Yancy Min on Unsplash At some point in my life I thought it would be a good idea to start forking git repos in GitHub instead of just starring them. I guess it started with a fear the repos might not exist in some point in the future and that I would like […]<\/p>\n

Read more →<\/a><\/p>\n","protected":false},"author":2,"featured_media":192,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[17],"tags":[33],"yoast_head":"\nDeleting unwanted forks from GitHub - Andr\u00e9 Jacobs<\/title>\n<meta name=\"description\" content=\"In this post I show you how to delete all of your unwanted GitHub forks in a flash. Deleting forks from GitHub is a very slow process to do by hand.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Deleting unwanted forks from GitHub - Andr\u00e9 Jacobs\" \/>\n<meta property=\"og:description\" content=\"In this post I show you how to delete all of your unwanted GitHub forks in a flash. Deleting forks from GitHub is a very slow process to do by hand.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/\" \/>\n<meta property=\"og:site_name\" content=\"Andr\u00e9 Jacobs\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-03T18:05:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-11T20:24:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/andrejacobs.org\/wp-content\/uploads\/2021\/03\/yancy-min-842ofHC6MaI-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1272\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andr\u00e9 Jacobs\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@andrejacobs81\" \/>\n<meta name=\"twitter:site\" content=\"@andrejacobs81\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andr\u00e9 Jacobs\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/\"},\"author\":{\"name\":\"Andr\u00e9 Jacobs\",\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\"},\"headline\":\"Deleting unwanted forks from GitHub\",\"datePublished\":\"2021-03-03T18:05:42+00:00\",\"dateModified\":\"2022-04-11T20:24:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/\"},\"wordCount\":432,\"publisher\":{\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\"},\"keywords\":[\"git\"],\"articleSection\":[\"DevOps\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/\",\"url\":\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/\",\"name\":\"Deleting unwanted forks from GitHub - Andr\u00e9 Jacobs\",\"isPartOf\":{\"@id\":\"https:\/\/andrejacobs.org\/#website\"},\"datePublished\":\"2021-03-03T18:05:42+00:00\",\"dateModified\":\"2022-04-11T20:24:24+00:00\",\"description\":\"In this post I show you how to delete all of your unwanted GitHub forks in a flash. Deleting forks from GitHub is a very slow process to do by hand.\",\"breadcrumb\":{\"@id\":\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/andrejacobs.org\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Deleting unwanted forks from GitHub\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/andrejacobs.org\/#website\",\"url\":\"https:\/\/andrejacobs.org\/\",\"name\":\"Andr\u00e9 Jacobs\",\"description\":\"iOS Development, Electronics, Robotics, Artificial Intelligence, Business and Health\",\"publisher\":{\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/andrejacobs.org\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68\",\"name\":\"Andr\u00e9 Jacobs\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg\",\"contentUrl\":\"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg\",\"width\":450,\"height\":450,\"caption\":\"Andr\u00e9 Jacobs\"},\"logo\":{\"@id\":\"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/andrejacobs.org\",\"https:\/\/www.youtube.com\/channel\/UCzqXvnd_UJ3sAzQkQBD-IVw\"],\"url\":\"https:\/\/andrejacobs.org\/author\/andre\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Deleting unwanted forks from GitHub - Andr\u00e9 Jacobs","description":"In this post I show you how to delete all of your unwanted GitHub forks in a flash. Deleting forks from GitHub is a very slow process to do by hand.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/","og_locale":"en_GB","og_type":"article","og_title":"Deleting unwanted forks from GitHub - Andr\u00e9 Jacobs","og_description":"In this post I show you how to delete all of your unwanted GitHub forks in a flash. Deleting forks from GitHub is a very slow process to do by hand.","og_url":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/","og_site_name":"Andr\u00e9 Jacobs","article_published_time":"2021-03-03T18:05:42+00:00","article_modified_time":"2022-04-11T20:24:24+00:00","og_image":[{"width":1920,"height":1272,"url":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2021\/03\/yancy-min-842ofHC6MaI-unsplash.jpg","type":"image\/jpeg"}],"author":"Andr\u00e9 Jacobs","twitter_card":"summary_large_image","twitter_creator":"@andrejacobs81","twitter_site":"@andrejacobs81","twitter_misc":{"Written by":"Andr\u00e9 Jacobs","Estimated reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/#article","isPartOf":{"@id":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/"},"author":{"name":"Andr\u00e9 Jacobs","@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68"},"headline":"Deleting unwanted forks from GitHub","datePublished":"2021-03-03T18:05:42+00:00","dateModified":"2022-04-11T20:24:24+00:00","mainEntityOfPage":{"@id":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/"},"wordCount":432,"publisher":{"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68"},"keywords":["git"],"articleSection":["DevOps"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/","url":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/","name":"Deleting unwanted forks from GitHub - Andr\u00e9 Jacobs","isPartOf":{"@id":"https:\/\/andrejacobs.org\/#website"},"datePublished":"2021-03-03T18:05:42+00:00","dateModified":"2022-04-11T20:24:24+00:00","description":"In this post I show you how to delete all of your unwanted GitHub forks in a flash. Deleting forks from GitHub is a very slow process to do by hand.","breadcrumb":{"@id":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/andrejacobs.org\/devops\/deleting-unwanted-forks-from-github\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/andrejacobs.org\/"},{"@type":"ListItem","position":2,"name":"Deleting unwanted forks from GitHub"}]},{"@type":"WebSite","@id":"https:\/\/andrejacobs.org\/#website","url":"https:\/\/andrejacobs.org\/","name":"Andr\u00e9 Jacobs","description":"iOS Development, Electronics, Robotics, Artificial Intelligence, Business and Health","publisher":{"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/andrejacobs.org\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/3d38360883015e883c80c2fb875c5a68","name":"Andr\u00e9 Jacobs","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/","url":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg","contentUrl":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2019\/03\/andre_jacobs.jpg","width":450,"height":450,"caption":"Andr\u00e9 Jacobs"},"logo":{"@id":"https:\/\/andrejacobs.org\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/andrejacobs.org","https:\/\/www.youtube.com\/channel\/UCzqXvnd_UJ3sAzQkQBD-IVw"],"url":"https:\/\/andrejacobs.org\/author\/andre\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/andrejacobs.org\/wp-content\/uploads\/2021\/03\/yancy-min-842ofHC6MaI-unsplash.jpg","_links":{"self":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts\/187"}],"collection":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/comments?post=187"}],"version-history":[{"count":3,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts\/187\/revisions"}],"predecessor-version":[{"id":193,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/posts\/187\/revisions\/193"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/media\/192"}],"wp:attachment":[{"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/media?parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/categories?post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andrejacobs.org\/wp-json\/wp\/v2\/tags?post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}