{"thread":{"id":"50333","subject":"Checkout branch and prune everything related to previous checkout (incl. LFS remains)","startedAt":"2019-01-27T00:16:47Z","lastAt":"2019-01-27T00:16:47Z","messageCount":1,"participants":["Mateusz Loskot"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"367726","messageId":"CABUeae_tm__uvHH74UARG805uTa2Sf0v6wYk=pmKvxxH3kvQ8A@mail.gmail.com","threadId":"50333","inReplyTo":null,"subject":"Checkout branch and prune everything related to previous checkout (incl. LFS remains)","fromName":"Mateusz Loskot","fromEmail":"mateusz@loskot.net","sentAt":"2019-01-27T00:16:17Z","receivedAt":"2019-01-27T00:16:47Z","isPatch":false,"sender":{"key":"mateusz@loskot.net","avatar":"https://gravatar.com/avatar/fe5a0ce8995d4986f5c46aad6353e21717808da58e4bc710da1a100e247be239?d=mp&s=160"},"body":"Hi,\n\nI have a repo of a superproject with number of submodules.\nlots of files of both are in Git LFS.\nThe repo comes with multiple long-lived release branches.\nThe complete clone transfers 20 GB of Git and Git LFS objects.\nCheckout of master deflates the total repo to 40 GB in total,\nthat is the objects and the working tree files together.\n\n\nLet's consider three separate clones as canonical way to create\nthree working copies, one per the long-lived branch:\n\n```\ngit clone --branch master      --recursive --jobs 8 https://repo repo_master\ngit clone --branch release/1.0 --recursive --jobs 8 https://repo repo_release1\ngit clone --branch release/2.0 --recursive --jobs 8 https://repo repo_release2\n\n```\n\nI'm trying to work out a network-optimised equivalent of the above:\n- clone once with the default master checked out\n- make multiple copies of the cloned repo\n- checkout release branches\n\nHow to checkout an existing branch fetched from remote,\ndelete the previous branch and clean up any remains?\n\nHow to clean up everything related to the previously checked out\nmaster and its working tree, any cached previous LFS downloads etc.?\n\nBut, to keep the history of origin/master.\n\nHere is what I have come up with for the the network-optimised workflow:\n\n```\ngit clone --branch master --recursive --jobs 8 https://repo repo_master\n\ncp -a repo_master repo_release1\ncp -a repo_master repo_release2\n\ncd repo_release1\ngit checkout -b release/1.0 --track origin/release/1.0\n\ngit pull\ngit submodule update --init --recursive --jobs 8\n\ngit branch -D master\n\ngit lfs prune\ngit submodule foreach --recursive git lfs prune\n\ngit lfs checkout\ngit submodule foreach --recursive git lfs checkout\n```\n\nDoes it look correct or any steps are missing/redundant?\n\nDoes it make sense to run any of these, at which point?\n\ngit gc --aggressive --prune=now\ngit submodule foreach --recursive git gc --aggressive --prune=now\n\nPlease, assume, no new commits will happen locally between the\n`git clone --branch master ...` and `cp -a repo_master ...`.\n\nBest regards,\n-- \nMateusz Loskot, http://mateusz.loskot.net\n"}]}