A place to cache linked articles (think custom and personal wayback machine)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.html 55KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. <!doctype html><!-- This is a valid HTML5 document. -->
  2. <!-- Screen readers, SEO, extensions and so on. -->
  3. <html lang="fr">
  4. <!-- Has to be within the first 1024 bytes, hence before the <title>
  5. See: https://www.w3.org/TR/2012/CR-html5-20121217/document-metadata.html#charset -->
  6. <meta charset="utf-8">
  7. <!-- Why no `X-UA-Compatible` meta: https://stackoverflow.com/a/6771584 -->
  8. <!-- The viewport meta is quite crowded and we are responsible for that.
  9. See: https://codepen.io/tigt/post/meta-viewport-for-2015 -->
  10. <meta name="viewport" content="width=device-width,initial-scale=1">
  11. <!-- Required to make a valid HTML5 document. -->
  12. <title>Git Branch Rename (archive) — David Larlet</title>
  13. <meta name="description" content="Publication mise en cache pour en conserver une trace.">
  14. <!-- That good ol' feed, subscribe :). -->
  15. <link rel="alternate" type="application/atom+xml" title="Feed" href="/david/log/">
  16. <!-- Generated from https://realfavicongenerator.net/ such a mess. -->
  17. <link rel="apple-touch-icon" sizes="180x180" href="/static/david/icons2/apple-touch-icon.png">
  18. <link rel="icon" type="image/png" sizes="32x32" href="/static/david/icons2/favicon-32x32.png">
  19. <link rel="icon" type="image/png" sizes="16x16" href="/static/david/icons2/favicon-16x16.png">
  20. <link rel="manifest" href="/static/david/icons2/site.webmanifest">
  21. <link rel="mask-icon" href="/static/david/icons2/safari-pinned-tab.svg" color="#07486c">
  22. <link rel="shortcut icon" href="/static/david/icons2/favicon.ico">
  23. <meta name="msapplication-TileColor" content="#f0f0ea">
  24. <meta name="msapplication-config" content="/static/david/icons2/browserconfig.xml">
  25. <meta name="theme-color" content="#f0f0ea">
  26. <!-- Documented, feel free to shoot an email. -->
  27. <link rel="stylesheet" href="/static/david/css/style_2020-06-19.css">
  28. <!-- See https://www.zachleat.com/web/comprehensive-webfonts/ for the trade-off. -->
  29. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  30. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  31. <link rel="preload" href="/static/david/css/fonts/triplicate_t4_poly_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: light), (prefers-color-scheme: no-preference)" crossorigin>
  32. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_regular.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  33. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_bold.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  34. <link rel="preload" href="/static/david/css/fonts/triplicate_t3_italic.woff2" as="font" type="font/woff2" media="(prefers-color-scheme: dark)" crossorigin>
  35. <script type="text/javascript">
  36. function toggleTheme(themeName) {
  37. document.documentElement.classList.toggle(
  38. 'forced-dark',
  39. themeName === 'dark'
  40. )
  41. document.documentElement.classList.toggle(
  42. 'forced-light',
  43. themeName === 'light'
  44. )
  45. }
  46. const selectedTheme = localStorage.getItem('theme')
  47. if (selectedTheme !== 'undefined') {
  48. toggleTheme(selectedTheme)
  49. }
  50. </script>
  51. <meta name="robots" content="noindex, nofollow">
  52. <meta content="origin-when-cross-origin" name="referrer">
  53. <!-- Canonical URL for SEO purposes -->
  54. <link rel="canonical" href="https://github.com/chancancode/branch-rename/blob/main/README.md">
  55. <body class="remarkdown h1-underline h2-underline h3-underline hr-center ul-star pre-tick">
  56. <article>
  57. <header>
  58. <h1>Git Branch Rename</h1>
  59. </header>
  60. <nav>
  61. <p class="center">
  62. <a href="/david/" title="Aller à l’accueil" tabindex="1">🏠</a>
  63. </p>
  64. </nav>
  65. <hr>
  66. <h2><a href="https://github.com/chancancode/branch-rename/blob/main/README.md">Source originale du contenu</a></h2>
  67. <main>
  68. <p>So, you want to rename a branch on Git/GitHub. The most common case of this is
  69. to rename the default "master" branch to something else, such as "main". We are
  70. going to use this as our example, but you may have a different use case in
  71. mind. If that's the case, just replace "master" and "main" to the source and
  72. target branches you have in mind.</p>
  73. <h2><a id="user-content-table-of-contents" class="anchor" aria-hidden="true" href="#table-of-contents"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Table of Contents</h2>
  74. <h2><a id="user-content-new-project" class="anchor" aria-hidden="true" href="#new-project"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>New Project</h2>
  75. <p>If you are starting a brand new project, you can follow these steps:</p>
  76. <ol>
  77. <li>
  78. <p><a href="https://github.com/new">Create a new repository on GitHub</a> to host your
  79. project with the following settings:</p>
  80. <ul>
  81. <li><strong>Repository template</strong>: No template</li>
  82. <li><strong>Initialize this repository with a README</strong>: Leave unchecked</li>
  83. <li><strong>Add .gitignore</strong>: None</li>
  84. <li><strong>Add a license</strong>: None</li>
  85. </ul>
  86. <p>If you wish to use any of these features (i.e. with settings different than
  87. the above), that is not a problem. However, GitHub will create the default
  88. "master" branch for you. In that case, clone the repository locally and
  89. follow the steps in the <a href="#simple-migration"><strong>Simple Migration</strong></a> section
  90. instead.</p>
  91. </li>
  92. <li>
  93. <p>Initialize an empty Git repository:</p>
  94. <div class="highlight highlight-source-shell"><pre>$ mkdir my-git-project
  95. $ <span class="pl-c1">cd</span> my-git-project
  96. $ git init <span class="pl-c1">.</span></pre></div>
  97. </li>
  98. <li>
  99. <p>Create the "main" branch:</p>
  100. </li>
  101. <li>
  102. <p>Work on your project and commit some changes. For example, add a README:</p>
  103. <div class="highlight highlight-source-shell"><pre>$ <span class="pl-c1">echo</span> <span class="pl-s"><span class="pl-pds">"</span># My Git Project<span class="pl-pds">"</span></span> <span class="pl-k">&gt;&gt;</span> README.md
  104. $ git add README.md
  105. $ git commit -m <span class="pl-s"><span class="pl-pds">"</span>Initial commit<span class="pl-pds">"</span></span></pre></div>
  106. </li>
  107. <li>
  108. <p>Push your commits to GitHub:</p>
  109. <div class="highlight highlight-source-shell"><pre>$ git remote add origin https://github.com/your-username/my-git-project.git
  110. $ git push -u origin main</pre></div>
  111. </li>
  112. </ol>
  113. <p>That's all! Since "main" was the first branch you pushed to GitHub, it will be
  114. set correctly as the default branch. We also never committed any changes to the
  115. "master" branch locally, it effectively never existed so there is nothing left
  116. to clean up. Enjoy your new project!</p>
  117. <h2><a id="user-content-simple-migration" class="anchor" aria-hidden="true" href="#simple-migration"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Simple Migration</h2>
  118. <p>If you have a small personal project and you are comfortable with just doing
  119. the rename right away, here are the steps you can take.</p>
  120. <p>Note that if this is a <a href="https://pages.github.com">GitHub Pages</a> repository and
  121. the content is stored on the "master" branch, then you cannot perform the
  122. migration at this time since GitHub Pages does not seem to support alternative
  123. default branch names yet. If you want, you may follow the steps in the <a href="#local-migration"><strong>Local
  124. Migration</strong></a> or <a href="#gradual-migration"><strong>Gradual Migration</strong></a>
  125. section partially to get your project ready.</p>
  126. <ol>
  127. <li>
  128. <p>Pull the latest commits from the "master" branch into your local repository:</p>
  129. <div class="highlight highlight-source-shell"><pre>$ <span class="pl-c1">cd</span> my-git-project
  130. $ git checkout master
  131. $ git pull origin master</pre></div>
  132. </li>
  133. <li>
  134. <p>Rename the local "master" branch to "main":</p>
  135. </li>
  136. <li>
  137. <p>Push the "main" branch to GitHub:</p>
  138. <div class="highlight highlight-source-shell"><pre>$ git push -u origin main</pre></div>
  139. </li>
  140. <li>
  141. <p><a href="https://help.github.com/en/github/administering-a-repository/setting-the-default-branch">Change the default branch on GitHub</a> to "main".</p>
  142. </li>
  143. <li>
  144. <p>If there are existing pull requests open against the "master" branch that
  145. you would like to keep, <a href="https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/changing-the-base-branch-of-a-pull-request">update their base branch</a> to
  146. the "main" branch. Otherwise, they will be closed automatically when we
  147. delete the remote "master" branch on GitHub.</p>
  148. </li>
  149. <li>
  150. <p>Delete your local "master" branch:</p>
  151. </li>
  152. <li>
  153. <p>Delete the remote "master" branch:</p>
  154. <div class="highlight highlight-source-shell"><pre>$ git push origin :master</pre></div>
  155. </li>
  156. </ol>
  157. <p>At this point, the migration is complete. However, as you work on the project,
  158. you may discover additional settings that you need to tweak to account for the
  159. rename. For example, you may have update the branch names in your CI config.</p>
  160. <h2><a id="user-content-gradual-migration" class="anchor" aria-hidden="true" href="#gradual-migration"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Gradual Migration</h2>
  161. <p>If you have a work or open-source repository with multiple contributors and
  162. forks, you may prefer to perform the migration gradually.</p>
  163. <p>These steps are for you if you find yourself in a similar scenario, where it is
  164. important to give everyone ample of time to prepare for the migration, changing
  165. local configs, adapting workflows, scripts and other automation to ensure a
  166. seamless migration.</p>
  167. <p>This gradual migration plan is intended to be spread out over a long period of
  168. time – weeks, or months. It uses all available tools on GitHub to provide as
  169. much advance notice as possible.</p>
  170. <p>For most organizations, this plan may be overly cautious and some of the steps
  171. may not be necessary. On the other hand, for a popular open-source project, it
  172. may not be feasible to get to the end and fully deprecate and remove the legacy
  173. "master" branch at all, due to compatibility requirements. Treat this plan as a
  174. template and adapt it for your own needs.</p>
  175. <p>Unlike the other sections, the steps here are a bit less exact and is intended
  176. for someone with a some prior experience with Git and GitHub. In practice, you
  177. will probably run into situations that causes deviations from the plan which
  178. would require some manual repair and adjustments. For example, pushes during a
  179. partial GitHub outage may cause the two branches to diverge and requires you
  180. to determine how to best reconcile the differences.</p>
  181. <h3><a id="user-content-phase-1-mirror-master-and-main" class="anchor" aria-hidden="true" href="#phase-1-mirror-master-and-main"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Phase 1: Mirror "master" and "main"</h3>
  182. <p>The goal of this phase is to make it <em>possible</em> to use the "main" branch name
  183. as an alternative. This allows some early adopters to start testing the new
  184. setup.</p>
  185. <ol>
  186. <li>
  187. <p>As always, make sure your local "master" branch is up-to-date.</p>
  188. </li>
  189. <li>
  190. <p>Create the new "main" branch:</p>
  191. </li>
  192. <li>
  193. <p>Add a <a href="https://github.com/features/actions">GitHub Actions</a> workflow file at
  194. <strong>.github/workflows/mirror-master-and-main.yml</strong> with the following:</p>
  195. <div class="highlight highlight-source-yaml"><pre><span class="pl-ent">name</span>: <span class="pl-s">Mirror "master" and "main" branches</span>
  196. <span class="pl-ent">on</span>:
  197. <span class="pl-ent">push</span>:
  198. <span class="pl-ent">branches</span>:
  199. - <span class="pl-s">master</span>
  200. - <span class="pl-s">main</span>
  201. <span class="pl-ent">jobs</span>:
  202. <span class="pl-ent">mirror</span>:
  203. <span class="pl-ent">runs-on</span>: <span class="pl-s">ubuntu-latest</span>
  204. <span class="pl-ent">steps</span>:
  205. - <span class="pl-ent">name</span>: <span class="pl-s">Mirror to "master"</span>
  206. <span class="pl-ent">uses</span>: <span class="pl-s">zofrex/mirror-branch@v1</span>
  207. <span class="pl-ent">with</span>:
  208. <span class="pl-ent">target-branch</span>: <span class="pl-s">master</span>
  209. <span class="pl-ent">force</span>: <span class="pl-c1">false</span>
  210. - <span class="pl-ent">name</span>: <span class="pl-s">Mirror to "main"</span>
  211. <span class="pl-ent">uses</span>: <span class="pl-s">zofrex/mirror-branch@v1</span>
  212. <span class="pl-ent">with</span>:
  213. <span class="pl-ent">target-branch</span>: <span class="pl-s">main</span>
  214. <span class="pl-ent">force</span>: <span class="pl-c1">false</span></pre></div>
  215. </li>
  216. <li>
  217. <p>Commit and your changes to the local "main" branch.</p>
  218. </li>
  219. <li>
  220. <p>Push your changes to the remote "main" branch:</p>
  221. <div class="highlight highlight-source-shell"><pre>$ git push -u origin main</pre></div>
  222. </li>
  223. </ol>
  224. <p>If things are working correctly, you should see the same commit pushed to the
  225. "master" branch shortly. You can monitor the progress and unexpected errors in
  226. the "Actions" tab in your repository.</p>
  227. <h4><a id="user-content-about-github-actions" class="anchor" aria-hidden="true" href="#about-github-actions"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>About GitHub Actions</h4>
  228. <p>You do not have to be already using GitHub Actions for this to work. You do not
  229. need to activate or enable the feature for your repository, simply pushing the
  230. workflow file to the is sufficient. All open-source repositories have unlimited
  231. GitHub Actions minutes, and all personal and team accounts comes with 2000-3000
  232. free GitHub Actions minutes for private repositories.</p>
  233. <p>If you already regularly uses up your free minutes, this may slightly increase
  234. your GitHub bills, but in practice, the workflow we added runs very quickly so
  235. the impact is very minimal. For reference, GitHub Actions are billed at $0.008
  236. USD per minute for private repositories, after the free quota is exhausted.</p>
  237. <p>This workflow will be triggered when commits are pushed to either the "master"
  238. or "main" branch. It uses the <a href="https://github.com/marketplace/actions/mirror-branch">Mirror Branch action</a> to
  239. update the branches using GitHub's API.</p>
  240. <h4><a id="user-content-interaction-with-branch-protection" class="anchor" aria-hidden="true" href="#interaction-with-branch-protection"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Interaction with Branch Protection</h4>
  241. <p>Unfortunately, if you have enabled <a href="https://help.github.com/en/github/administering-a-repository/configuring-protected-branches">branch protection</a> on
  242. the "master" branch, the push from the mirroring action may be rejected. For
  243. example, if you had enabled "Require pull request reviews before merging", then
  244. this would not work as the changes are expected to be submitted via a pull
  245. request with reviews.</p>
  246. <p>A possible workaround is to disable the "Include administrators" checkbox in
  247. the branch protection settings for the "master" branch and configure the script
  248. to push the commits as an administrator:</p>
  249. <ol>
  250. <li>
  251. <p>Login as an administrator on GitHub. You may also want to consider creating
  252. a new account specifically for this purpose.</p>
  253. </li>
  254. <li>
  255. <p>Generate a <a href="https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line">personal access token</a> with the "repo"
  256. scope (and the "public_repo" scope, if needed).</p>
  257. </li>
  258. <li>
  259. <p><a href="https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository">Add it as a secret</a> to the repository.</p>
  260. </li>
  261. <li>
  262. <p>Change the "Checkout" step in the mirror workflow to use the new deploy key:</p>
  263. <div class="highlight highlight-source-yaml"><pre>- <span class="pl-ent">name</span>: <span class="pl-s">Checkout</span>
  264. <span class="pl-ent">uses</span>: <span class="pl-s">actions/checkout@v2</span>
  265. <span class="pl-ent">with</span>:
  266. <span class="pl-ent">token</span>: <span class="pl-s">${{ secrets.DEPLOY_TOKEN }}</span></pre></div>
  267. <p>Here, <code>DEPLOY_TOKEN</code> is the name you picked from step 3.</p>
  268. </li>
  269. </ol>
  270. <p>Alternatively, an SSH key for the administrator can be used instead of a
  271. personal access token, via the <code>ssh-key</code> argument. See the documentation for
  272. the <a href="https://github.com/actions/checkout">checkout action</a> for more details.</p>
  273. <h4><a id="user-content-interaction-with-other-github-action-workflows" class="anchor" aria-hidden="true" href="#interaction-with-other-github-action-workflows"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Interaction with Other GitHub Action Workflows</h4>
  274. <p>By default, when pushing commits from within the GitHub Actions job, it does
  275. not trigger additional GitHub Actions workflow to run. For example, when a
  276. contributor pushes to the "main" branch, it will trigger any GitHub Actions
  277. that normally runs on the "main" branch's push events, including the one we
  278. added here. However, when our mirror workflow pushes the same commit to the
  279. "master" branch, it will not trigger any workflow that normally runs on the
  280. "master" branch's push events.</p>
  281. <p>For this reason, you may want to update existing workflows that runs on the
  282. "master" branch to also run on the "main" branch, as we did in our mirror
  283. workflow file (the <code>on.push.branches</code> config key). This is the recommended
  284. approach as it ensures only a single build per push.</p>
  285. <p>Alternatively, if it is important to you that workflows are triggered by pushes
  286. from the mirror workflow, you can accomplish this by supplying an alternative
  287. SSH key to the <a href="https://github.com/actions/checkout">checkout action</a>:</p>
  288. <ol>
  289. <li>
  290. <p><a href="https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent">Generate a new SSH key</a> locally. Don't worry about adding
  291. it to the ssh-agent.</p>
  292. </li>
  293. <li>
  294. <p>Find the generated <em>public key</em> and <a href="https://developer.github.com/v3/guides/managing-deploy-keys/#deploy-keys">add it as a deploy key</a>
  295. to the repository. Be sure to select "Allow write access".</p>
  296. </li>
  297. <li>
  298. <p>Find the generated <em>private key</em> and <a href="https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets-for-a-repository">add it as a secret</a> to the
  299. repository.</p>
  300. </li>
  301. <li>
  302. <p>Change the "Checkout" step in the mirror workflow to use the new deploy key:</p>
  303. <div class="highlight highlight-source-yaml"><pre>- <span class="pl-ent">name</span>: <span class="pl-s">Checkout</span>
  304. <span class="pl-ent">uses</span>: <span class="pl-s">actions/checkout@v2</span>
  305. <span class="pl-ent">with</span>:
  306. <span class="pl-ent">ssh-key</span>: <span class="pl-s">${{ secrets.DEPLOY_KEY }}</span></pre></div>
  307. <p>Here, <code>DEPLOY_KEY</code> is the name you picked from step 3.</p>
  308. </li>
  309. </ol>
  310. <p>With this, the mirror workflow will authenticate with GitHub using the deploy
  311. key instead of the default token when pushing commits, triggering any workflows
  312. as if a regular user had pushed those commits. This does not change the author
  313. or committer on the commits.</p>
  314. <h4><a id="user-content-real-world-example" class="anchor" aria-hidden="true" href="#real-world-example"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Real World Example</h4>
  315. <p>See <a href="https://github.com/chancancode/ember-concurrency-async/commit/afbacf7088e473dd056138109e00d8749b95b2d0">this commit</a> and <a href="https://github.com/chancancode/ember-concurrency-async/runs/788797792?check_suite_focus=true">the resulting workflow run</a>
  316. for an example of this working in action. Note that the code in the commit may
  317. be outdated by the time you read this – refer to the above for the latest
  318. instructions.</p>
  319. <h4><a id="user-content-next-steps" class="anchor" aria-hidden="true" href="#next-steps"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Next Steps</h4>
  320. <p>After verifying that everything is working as intended, you can start inviting
  321. the early adopters to start pushing to the "main" branch. The easiest way to do
  322. this is to rename the local "master" branch:</p>
  323. <div class="highlight highlight-source-shell"><pre>$ <span class="pl-c1">cd</span> my-git-project
  324. $ git checkout master
  325. $ git branch -m main
  326. $ git branch -u origin/main</pre></div>
  327. <p>This would also be a good time to start changing any automation or external
  328. services to the "main" branch to ensure that everything is working as expected.</p>
  329. <h3><a id="user-content-phase-2-change-the-default-branch-to-main-deprecate-master" class="anchor" aria-hidden="true" href="#phase-2-change-the-default-branch-to-main-deprecate-master"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Phase 2: Change the default branch to "main", deprecate "master"</h3>
  330. <p>After verifying the viability of the rename during the previous phase, the goal
  331. of this phase is to set "main" as the default branch and start issuing
  332. deprecation warnings when the legacy "master" branch is used.</p>
  333. <ol>
  334. <li>
  335. <p><a href="https://help.github.com/en/github/administering-a-repository/setting-the-default-branch">Change the default branch on GitHub</a> to "main".</p>
  336. </li>
  337. <li>
  338. <p>Add a <a href="https://github.com/features/actions">GitHub Actions</a> workflow file at
  339. <strong>.github/workflows/deprecate-master-branch.yml</strong> with the following:</p>
  340. <div class="highlight highlight-source-yaml"><pre><span class="pl-ent">name</span>: <span class="pl-s">Deprecate "master" branch</span>
  341. <span class="pl-ent">on</span>:
  342. <span class="pl-ent">push</span>:
  343. <span class="pl-ent">branches</span>:
  344. - <span class="pl-s">master</span>
  345. <span class="pl-ent">pull_request</span>:
  346. <span class="pl-ent">branches</span>:
  347. - <span class="pl-s">master</span>
  348. <span class="pl-ent">jobs</span>:
  349. <span class="pl-ent">on-push</span>:
  350. <span class="pl-ent">runs-on</span>: <span class="pl-s">ubuntu-latest</span>
  351. <span class="pl-ent">if</span>: <span class="pl-s">${{ github.event_name == 'push' }}</span>
  352. <span class="pl-ent">steps</span>:
  353. - <span class="pl-ent">name</span>: <span class="pl-s">Deprecation</span>
  354. <span class="pl-ent">uses</span>: <span class="pl-s">peter-evans/commit-comment@v1</span>
  355. <span class="pl-ent">with</span>:
  356. <span class="pl-ent">body</span>: <span class="pl-s">|</span>
  357. <span class="pl-s"> Hello @${{ github.event.sender.login }}!</span>
  358. <span class="pl-s"/>
  359. <span class="pl-s"> I see that you have pushed some commits to the "master" branch. We are in the process of renaming the "master" branch to "main" in this repository.</span>
  360. <span class="pl-s"/>
  361. <span class="pl-s"> :warning: **The "master" branch is deprecated and will be removed from this repository in the future.**</span>
  362. <span class="pl-s"/>
  363. <span class="pl-s"> Please migrate your local repository by renaming the "master" branch to "main":</span>
  364. <span class="pl-s"/>
  365. <span class="pl-s"> ```bash</span>
  366. <span class="pl-s"> $ cd my-git-project</span>
  367. <span class="pl-s"> $ git checkout master</span>
  368. <span class="pl-s"> $ git branch -m main</span>
  369. <span class="pl-s"> $ git branch -u origin/main</span>
  370. <span class="pl-s"> ```</span>
  371. <span class="pl-s"/>
  372. <span class="pl-s"> Before merging pull requests, ensure their base branch is set to "main" instead of "master". For more information on how to do this, refer to [this GitHub support article][1].</span>
  373. <span class="pl-s"/>
  374. <span class="pl-s"> [1]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/changing-the-base-branch-of-a-pull-request</span>
  375. <span class="pl-s"/>
  376. <span class="pl-s"/> <span class="pl-ent">on-pull-request</span>:
  377. <span class="pl-ent">runs-on</span>: <span class="pl-s">ubuntu-latest</span>
  378. <span class="pl-ent">if</span>: <span class="pl-s">${{ github.event_name == 'pull_request' }}</span>
  379. <span class="pl-ent">env</span>:
  380. <span class="pl-ent">DEPRECATION_MESSAGE</span>: <span class="pl-s">|</span>
  381. <span class="pl-s"> Hello @${{ github.event.sender.login }}!</span>
  382. <span class="pl-s"/>
  383. <span class="pl-s"> I see that you have opened a pull request against the "master" branch. We are in the process of renaming the "master" branch to "main" in this repository.</span>
  384. <span class="pl-s"/>
  385. <span class="pl-s"> :warning: **The "master" branch is deprecated and will be removed from this repository in the future.**</span>
  386. <span class="pl-s"/>
  387. <span class="pl-s"> Please migrate your local repository by renaming the "master" branch to "main":</span>
  388. <span class="pl-s"/>
  389. <span class="pl-s"> ```bash</span>
  390. <span class="pl-s"> $ cd my-git-project</span>
  391. <span class="pl-s"> $ git checkout master</span>
  392. <span class="pl-s"> $ git branch -m main</span>
  393. <span class="pl-s"> $ git branch -u origin/main</span>
  394. <span class="pl-s"> ```</span>
  395. <span class="pl-s"/>
  396. <span class="pl-s"> Please also set the base branch for this pull request to "main" instead of "master". For more information on how to do this, refer to [this GitHub support article][1].</span>
  397. <span class="pl-s"/>
  398. <span class="pl-s"> [1]: https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/changing-the-base-branch-of-a-pull-request</span>
  399. <span class="pl-s"/> <span class="pl-ent">steps</span>:
  400. - <span class="pl-ent">name</span>: <span class="pl-s">Deprecation</span>
  401. <span class="pl-ent">if</span>: <span class="pl-s">${{ github.event.pull_request.head.repo.fork == false }}</span>
  402. <span class="pl-ent">uses</span>: <span class="pl-s">peter-evans/create-or-update-comment@v1</span>
  403. <span class="pl-ent">with</span>:
  404. <span class="pl-ent">issue-number</span>: <span class="pl-s">${{ github.event.number }}</span>
  405. <span class="pl-ent">body</span>: <span class="pl-s">${{ env.DEPRECATION_MESSAGE }}</span>
  406. - <span class="pl-ent">name</span>: <span class="pl-s">Deprecation</span>
  407. <span class="pl-ent">if</span>: <span class="pl-s">${{ github.event.pull_request.head.repo.fork == true }}</span>
  408. <span class="pl-ent">run</span>: <span class="pl-s">|</span>
  409. <span class="pl-s"> echo "$DEPRECATION_MESSAGE"</span>
  410. <span class="pl-s"> echo '::error::Please set the base branch for this pull request to "main" instead of "master".'</span>
  411. <span class="pl-s"> exit 1</span></pre></div>
  412. </li>
  413. <li>
  414. <p>Commit and push your changes to the "main" branch.</p>
  415. </li>
  416. </ol>
  417. <p>We added a workflow file that triggers whenever a contributor pushes to or
  418. opens a pull request against the "master" branch.</p>
  419. <p>The workflow adds a comment to the commit or pull request, notifying the
  420. contributor that the "master" branch has been deprecated, along with the steps
  421. they need to take to migrate their local repository and changes they need to
  422. make it to the pull request.</p>
  423. <p>It is recommended that you customize the messages with additional information
  424. relevant for your organization. For example, you may want to include a link to
  425. a tracking issue for additional context, or ways for the contributor to ask for
  426. additional assistance if needed.</p>
  427. <h4><a id="user-content-limitations-of-github-actions-in-forks" class="anchor" aria-hidden="true" href="#limitations-of-github-actions-in-forks"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Limitations of GitHub Actions in Forks</h4>
  428. <p>Unfortunately, due to limitations of GitHub Actions, it is not possible to add
  429. a pull request comment from the workflow when the pull request originated from
  430. a fork, which is very common in open-source repositories. As a workaround, the
  431. workflow prints the deprecation message to the logs and fails the build.</p>
  432. <h4><a id="user-content-real-world-example-1" class="anchor" aria-hidden="true" href="#real-world-example-1"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Real World Example</h4>
  433. <p>See <a href="https://github.com/chancancode/ember-concurrency-async/commit/7f3509b4363f3fcdb3275ec136c4b5766f39c192">this commit</a> and <a href="https://github.com/chancancode/ember-concurrency-async/pull/5">this pull request</a> for an
  434. example of this working in action. Note that the code in the commit may be
  435. outdated by the time you read this – refer to the above for the latest
  436. instructions.</p>
  437. <h4><a id="user-content-next-steps-1" class="anchor" aria-hidden="true" href="#next-steps-1"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Next Steps</h4>
  438. <p>This would be a good time to start updating any internal and external links to
  439. the "master" branch. A common example would be automatically generated links to
  440. source code from the API documentation.</p>
  441. <h3><a id="user-content-phase-3-complete-the-migration" class="anchor" aria-hidden="true" href="#phase-3-complete-the-migration"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Phase 3: Complete the migration</h3>
  442. <p>After a successful phase 2 rollout, it is time to plan for completing the
  443. migration. However, what completion means is going to be different depending on
  444. your situation.</p>
  445. <p>For private work repositories, the legacy "master" branch can likely be removed
  446. from the repository after giving team members a few weeks to migrate. Don't
  447. forget to remove the workflow files as well.</p>
  448. <p>For open-source repositories with lots of contributors, you may want to move a
  449. lot slower. Monitor the Actions tab of the repository to see how often the
  450. deprecation workflow is triggered. When the activity diminishes, it may be good
  451. indication that the legacy "master" branch is no longer needed.</p>
  452. <h4><a id="user-content-soft-removal" class="anchor" aria-hidden="true" href="#soft-removal"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Soft Removal</h4>
  453. <p>As an alternative to removing the branch right away, you may want to consider
  454. pushing a final commit to the branch, removing all files but leave behind a
  455. README file explaining that branch has been moved, along with the steps they
  456. need to take in order to migrate their local repository.</p>
  457. <h4><a id="user-content-url-considerations" class="anchor" aria-hidden="true" href="#url-considerations"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>URL Considerations</h4>
  458. <p>It is also important to consider URL breakages, as links that points to the
  459. files on the "master" branch will stop working once the branch is removed,
  460. including with the soft-removal method described above.</p>
  461. <p>The impact of this has to be evaluated contextually, but it is important to
  462. note that the scope of the breakage is fairly limited, as this only directly
  463. impacts URLs that links to the "master" branch directly. Links pointing to the
  464. active development branch of repository is quite fragile (especially with line
  465. numbers) and often breaks for other reasons.</p>
  466. <p>For example, a refactor that moves around files or switching from JavaScript to
  467. TypeScript would invalidate these URLs. This sort of activity is fairly common
  468. on an active code repository and is usually performed without taking the URL
  469. consideration in mind. For this reason, it is considered a best practice to use
  470. SHA-based <a href="https://help.github.com/en/github/managing-files-in-a-repository/getting-permanent-links-to-files">permanent links</a> in most situations. These links
  471. are unaffected by the branch rename.</p>
  472. <h4><a id="user-content-packages-considerations" class="anchor" aria-hidden="true" href="#packages-considerations"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Packages Considerations</h4>
  473. <p>For repositories containing <em>installable packages</em>, there are some additional
  474. considerations. Many package managers allow for installing packages from a Git
  475. repository. For example, in npm and yarn, dependencies can be a string like
  476. "username/repo" or "username/repo#branch" in lieu of version range. Likewise,
  477. GitHub Actions are installed using repository and branch references, and it is
  478. a relatively common practice to point an action at the "master" branch.</p>
  479. <p>In these cases, the decision on whether to remove the legacy "master" branch
  480. has to be made carefully. Here are some examples of things to investigate
  481. and consider:</p>
  482. <ul>
  483. <li>
  484. <p>When the branch is omitted from the specifier (e.g. "username/repo"), does
  485. the package manager in your ecosystem hard-code the default to "master" on
  486. the client, or does it respect the remote HEAD ref?</p>
  487. </li>
  488. <li>
  489. <p>Does the package manager use a lockfile, and if so, does it serialize the
  490. branch name (as opposed to the resolved SHA) into the lockfile?</p>
  491. </li>
  492. <li>
  493. <p>Does the package manager maintain a cache of cloned repositories, and if so
  494. do they recover gracefully to a remote branch disappearing?</p>
  495. </li>
  496. </ul>
  497. <p>The answer to these questions affects the potential impact to your end-users
  498. if the legacy "master" branch is removed from the repository. For some, the
  499. end-state of the migration may be to keep the "master" branch permanently as a
  500. read-only mirror, or it may be sufficient to freeze the branch's content and
  501. stop providing updates there. For others, the potential breakage maybe small
  502. enough that it is can be easily justified.</p>
  503. <p>While the workflows added in phase 2 are effective for deprecating <em>writes</em> to
  504. the legacy "master" branch. Unfortunately, Git and GitHub do not offer the
  505. ability to do the same for <em>reads</em> to the branch.</p>
  506. <p>However, you may be able to use features from the package manager to accomplish
  507. a similar result. For example, instead of mirroring the "main" branch to the
  508. "master" branch exactly, you could add a post-install hook to the version on
  509. "master" to issue the deprecation message for any potential consumers.</p>
  510. <h4><a id="user-content-a-concrete-example" class="anchor" aria-hidden="true" href="#a-concrete-example"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>A Concrete Example</h4>
  511. <p>Using the Node.js ecosystem as an example, we can put these considerations into
  512. context, based on preliminary testing with npm and yarn classic (v1). If you
  513. found different results in your own testing, or with other package managers
  514. (pnpm, yarn v2, etc), please file an issue here.</p>
  515. <ul>
  516. <li>
  517. <p>The popular package managers in the ecosystem support installing packages
  518. from git, by specifying "username/repo" or "username/repo#branch" in the
  519. dependencies section of package.json.</p>
  520. </li>
  521. <li>
  522. <p>When a branch name is not specified, the popular package managers defaults to
  523. the remote HEAD ref, which is set by the default branch on GitHub, instead of
  524. hardcoding to the "master" branch in the client.</p>
  525. </li>
  526. <li>
  527. <p>The popular package managers uses a lockfile by default. They serialize the
  528. resolved SHA into the lockfiles, as long as the commits referred to by these
  529. SHAs remain reachable on the remote repository, they will install just fine
  530. when using a lockfile. In the case of a branch rename, this is not an issue,
  531. as the history and commits will remain intact.</p>
  532. </li>
  533. <li>
  534. <p>When installing without a lockfile, the popular package managers will fetch
  535. the latest commit from the repository. Renaming the remote branch did not
  536. appear to cause any issues, either because the repositories are not cached,
  537. or the clients are able to recover gracefully from a "missing" remote branch.</p>
  538. </li>
  539. <li>
  540. <p>Post-install hooks are supported. However, yarn classic <a href="https://github.com/yarnpkg/yarn/issues/5476">hides the output
  541. produced by these scripts</a> if
  542. they are successful (exit cleanly with exit code 0). However, when they fail,
  543. they output <em>is</em> shown to the user.</p>
  544. </li>
  545. <li>
  546. <p>Generally speaking, the ecosystem has strong norms and expectations around
  547. adhering to <a href="https://semver.org" rel="nofollow">semantic versioning</a>. Usually, breaking changes are only
  548. expected on major version bumps.</p>
  549. </li>
  550. <li>
  551. <p>By using a Git dependency instead of specifying a semver range, they are
  552. explicitly opting out of the normal semver guarantee, and breakages are to be
  553. expected. No one could reasonably expect that pointing a dependency to the
  554. active development branch without using a lockfile will result in a stable
  555. system.</p>
  556. </li>
  557. </ul>
  558. <p>Given these findings, here is a concrete proposal for a maximally graceful
  559. completion plan:</p>
  560. <ol>
  561. <li>
  562. <p>Stop providing updates to the "master" branch by removing the mirroring
  563. workflow added in phase 1.</p>
  564. </li>
  565. <li>
  566. <p>Push a commit the "master" branch, updating the README as well as adding a
  567. deprecation message to the runtime code (the <code>main</code> entry point):</p>
  568. <div class="highlight highlight-source-js"><pre><span class="pl-c">// index.js</span>
  569. <span class="pl-k">let</span> <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">'npm update my-git-project'</span><span class="pl-kos">;</span>
  570. <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">npm_execpath</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">npm_execpath</span><span class="pl-kos">.</span><span class="pl-en">indexOf</span><span class="pl-kos">(</span><span class="pl-s">'yarn'</span><span class="pl-kos">)</span> !== <span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  571. <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">'yarn upgrade my-git-project'</span><span class="pl-kos">;</span>
  572. <span class="pl-kos">}</span>
  573. <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">warn</span><span class="pl-kos">(</span>
  574. <span class="pl-s">`You are running a deprecated copy of the "my-git-project" installed `</span> <span class="pl-c1">+</span>
  575. <span class="pl-s">`from the "master" branch of our repository. The "master" branch is `</span> <span class="pl-c1">+</span>
  576. <span class="pl-s">`deprecated and no longer receives any updates. The branch will soon `</span> <span class="pl-c1">+</span>
  577. <span class="pl-s">`be removed from our repository, at which point the package will fail `</span> <span class="pl-c1">+</span>
  578. <span class="pl-s">`to install.\n\n`</span> <span class="pl-c1">+</span>
  579. <span class="pl-s">`To fix this issue, please modify your package.json and change the `</span> <span class="pl-c1">+</span>
  580. <span class="pl-s">`"my-git-project" dependency from "my-repo/my-git-project#master" to `</span> <span class="pl-c1">+</span>
  581. <span class="pl-s">`"my-repo/my-git-project" or a valid semver range. After making the `</span> <span class="pl-c1">+</span>
  582. <span class="pl-s">`change, run "<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">command</span><span class="pl-kos">}</span></span>" to update the package.`</span>
  583. <span class="pl-kos">)</span><span class="pl-kos">;</span>
  584. <span class="pl-c">// ...rest of index.js</span></pre></div>
  585. </li>
  586. <li>
  587. <p>When releasing the next major version of the package, push another commit to
  588. the "master" branch, remove all files from the branch, leaving behind only a
  589. minimal README file, package.json and index.js:</p>
  590. <div class="highlight highlight-source-js"><pre><span class="pl-c">// package.json</span>
  591. <span class="pl-kos">{</span>
  592. <span class="pl-s">"name"</span>: <span class="pl-s">"my-git-project"</span><span class="pl-kos">,</span>
  593. <span class="pl-s">"scripts"</span>: <span class="pl-kos">{</span>
  594. <span class="pl-s">"postinstall"</span>: <span class="pl-s">"node index.js"</span>
  595. <span class="pl-kos">}</span>
  596. <span class="pl-kos">}</span></pre></div>
  597. <div class="highlight highlight-source-js"><pre><span class="pl-c">// index.js</span>
  598. <span class="pl-k">let</span> <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">'npm update my-git-project'</span><span class="pl-kos">;</span>
  599. <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">npm_execpath</span> <span class="pl-c1">&amp;&amp;</span> <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">npm_execpath</span><span class="pl-kos">.</span><span class="pl-en">indexOf</span><span class="pl-kos">(</span><span class="pl-s">'yarn'</span><span class="pl-kos">)</span> !== <span class="pl-c1">-</span><span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  600. <span class="pl-s1">command</span> <span class="pl-c1">=</span> <span class="pl-s">'yarn upgrade my-git-project'</span><span class="pl-kos">;</span>
  601. <span class="pl-kos">}</span>
  602. <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">error</span><span class="pl-kos">(</span>
  603. <span class="pl-s">`You have installed "my-git-project" from the "master" branch of our `</span> <span class="pl-c1">+</span>
  604. <span class="pl-s">`repository. The "master" branch has been official retired.\n\n`</span> <span class="pl-c1">+</span>
  605. <span class="pl-s">`To fix this issue, please modify your package.json and change the `</span> <span class="pl-c1">+</span>
  606. <span class="pl-s">`"my-git-project" dependency from "my-repo/my-git-project#master" to `</span> <span class="pl-c1">+</span>
  607. <span class="pl-s">`"my-repo/my-git-project" or a valid semver range. After making the `</span> <span class="pl-c1">+</span>
  608. <span class="pl-s">`change, run "<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">command</span><span class="pl-kos">}</span></span>" to update the package.`</span>
  609. <span class="pl-kos">)</span><span class="pl-kos">;</span>
  610. <span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-en">exit</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
  611. </li>
  612. <li>
  613. <p>After some time, the master branch can be removed from the repository. This
  614. does not constitute a breaking change, as the package already ceased to
  615. function as of the previous commit. It was just a courteous message to ease
  616. confusion and provide actionable instructions for fixing the issue.</p>
  617. </li>
  618. </ol>
  619. <p>For most projects and organizations, this amount of notice is probably not
  620. necessary or warranted, but it showcases the available tools and techniques,
  621. and demonstrates that there can be a good migration path even under very strict
  622. compatibility requirements. As always, use these steps as a template and tailor
  623. them to your own needs.</p>
  624. <h2><a id="user-content-local-migration" class="anchor" aria-hidden="true" href="#local-migration"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>Local Migration</h2>
  625. <p>Finally, if you are working on a repository you don't control, and you would
  626. like to refer to your local branch with a different name without making any
  627. changes to the upstream project, you can rename your local "master" branch to
  628. "main" with these steps:</p>
  629. <div class="highlight highlight-source-shell"><pre>$ <span class="pl-c1">cd</span> my-git-project
  630. $ git checkout master
  631. $ git branch -m main
  632. $ git branch -u origin/master</pre></div>
  633. <p>This renames the local branch to "main" but sets the remote tracking branch to
  634. "master".</p>
  635. <h2><a id="user-content-license" class="anchor" aria-hidden="true" href="#license"><svg class="octicon octicon-link" viewbox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"/></svg></a>License</h2>
  636. <p>This content in this repository, including this documentation and code examples
  637. are licensed under the <a href="https://creativecommons.org/share-your-work/public-domain/cc0/" rel="nofollow">CC0 "No Rights Reserved"</a> public domain
  638. license. Feel free to reproduce and adapt this work into your own proposals,
  639. documentation, etc.</p>
  640. <p>Attribution is not necessary. However, this guide receives constant updates to
  641. reflect current best-practice and solutions based implementation feedback, so
  642. a reference to this repository may be helpful.</p>
  643. </main>
  644. </article>
  645. <hr>
  646. <footer>
  647. <p>
  648. <a href="/david/" title="Aller à l’accueil">🏠</a> •
  649. <a href="/david/log/" title="Accès au flux RSS">🤖</a> •
  650. <a href="http://larlet.com" title="Go to my English profile" data-instant>🇨🇦</a> •
  651. <a href="mailto:david%40larlet.fr" title="Envoyer un courriel">📮</a> •
  652. <abbr title="Hébergeur : Alwaysdata, 62 rue Tiquetonne 75002 Paris, +33184162340">🧚</abbr>
  653. </p>
  654. <template id="theme-selector">
  655. <form>
  656. <fieldset>
  657. <legend>Thème</legend>
  658. <label>
  659. <input type="radio" value="auto" name="chosen-color-scheme" checked> Auto
  660. </label>
  661. <label>
  662. <input type="radio" value="dark" name="chosen-color-scheme"> Foncé
  663. </label>
  664. <label>
  665. <input type="radio" value="light" name="chosen-color-scheme"> Clair
  666. </label>
  667. </fieldset>
  668. </form>
  669. </template>
  670. </footer>
  671. <script type="text/javascript">
  672. function loadThemeForm(templateName) {
  673. const themeSelectorTemplate = document.querySelector(templateName)
  674. const form = themeSelectorTemplate.content.firstElementChild
  675. themeSelectorTemplate.replaceWith(form)
  676. form.addEventListener('change', (e) => {
  677. const chosenColorScheme = e.target.value
  678. localStorage.setItem('theme', chosenColorScheme)
  679. toggleTheme(chosenColorScheme)
  680. })
  681. const selectedTheme = localStorage.getItem('theme')
  682. if (selectedTheme && selectedTheme !== 'undefined') {
  683. form.querySelector(`[value="${selectedTheme}"]`).checked = true
  684. }
  685. }
  686. const prefersColorSchemeDark = '(prefers-color-scheme: dark)'
  687. window.addEventListener('load', () => {
  688. let hasDarkRules = false
  689. for (const styleSheet of Array.from(document.styleSheets)) {
  690. let mediaRules = []
  691. for (const cssRule of styleSheet.cssRules) {
  692. if (cssRule.type !== CSSRule.MEDIA_RULE) {
  693. continue
  694. }
  695. // WARNING: Safari does not have/supports `conditionText`.
  696. if (cssRule.conditionText) {
  697. if (cssRule.conditionText !== prefersColorSchemeDark) {
  698. continue
  699. }
  700. } else {
  701. if (cssRule.cssText.startsWith(prefersColorSchemeDark)) {
  702. continue
  703. }
  704. }
  705. mediaRules = mediaRules.concat(Array.from(cssRule.cssRules))
  706. }
  707. // WARNING: do not try to insert a Rule to a styleSheet you are
  708. // currently iterating on, otherwise the browser will be stuck
  709. // in a infinite loop…
  710. for (const mediaRule of mediaRules) {
  711. styleSheet.insertRule(mediaRule.cssText)
  712. hasDarkRules = true
  713. }
  714. }
  715. if (hasDarkRules) {
  716. loadThemeForm('#theme-selector')
  717. }
  718. })
  719. </script>
  720. </body>
  721. </html>