import{_ as a,o as i,c as t,ae as e}from"./chunks/framework.B1nRs-GM.js";const F=JSON.parse('{"title":"Новый проект от шаблона","description":"Старт нового приложения от шаблонного репозитория с правильной историей веток.","frontmatter":{"title":"Новый проект от шаблона","description":"Старт нового приложения от шаблонного репозитория с правильной историей веток."},"headers":[],"relativePath":"setup/clean-repository.md","filePath":"setup/clean-repository.md"}'),p={name:"setup/clean-repository.md"};function n(l,s,h,k,d,r){return i(),t("div",null,[...s[0]||(s[0]=[e(`
Этот сценарий подходит, когда репозиторий приложения ещё пустой или его можно безопасно пересоздать от шаблона.
Целевая модель:
templates/master -> template -> sync/* -> masterЕсть два репозитория:
template repo = репозиторий шаблона
app repo = репозиторий приложенияВ обоих репозиториях основная ветка называется master.
В репозитории шаблона:
cd /path/to/template-repo
git switch masterЕсли это пустой репозиторий, добавьте первый файл и запушьте master:
printf "# Template Repository\\n\\nBase template version: v1\\n" > README.md
git add README.md
git commit -m "docs: добавить базовый шаблон"
git push -u origin masterВ репозитории приложения:
cd /path/to/app-repo
git remote add templates <template-repo-url>
git fetch templatesСоздайте ветку template от шаблона:
git switch -c template templates/master
git push -u origin templateСоздайте ветку приложения master от template:
git switch -c master templateДобавьте слой приложения:
mkdir -p app
printf "Application code v1\\n" > app/app.txt
git add app/app.txt
git commit -m "feat: добавить слой приложения"
git push -u origin masterПосле этого история выглядит так:
template: T1
master: T1---A1Где T1 — коммит шаблона, а A1 — коммит приложения.
Можно сделать так, чтобы на ветке template:
git pull тянул из templates/master
git push пушил в origin/templateКоманды:
git config branch.template.remote templates
git config branch.template.merge refs/heads/master
git config branch.template.pushRemote originДополнительно можно запретить случайный push в репозиторий шаблона:
git remote set-url --push templates DISABLEDПосле первичной настройки постоянные ветки такие:
template = чистый шаблон
master = приложениеОбновления шаблона выполняются через временные ветки sync/* по инструкции Обычное обновление шаблона.