---
# System prepended metadata

title: Creating a Template Repository for sharing lessons

---

# Creating a Template Repository for sharing lessons

## Setting up the Template Repository locally
- Create a new folder on your local machine to hold repository code
- create a new repo inside of that folder 
- checkout a dummy branch: `git checkout -b dummy`
- create a blank README.md file in the folder and make an initial commit
- checkout a main branch: `git checkout -b main`
- remove the README.md file and make another commit.
- remove the dummy branch: `git branch -D dummy`
- checkout empty lesson branches from here following instructions below:
- **for each lesson in the phase** 
	- checkout a branch for each lesson's starter code–named starting with the lesson number (01_begin_lesson_name, 02_begin_lesson_name, etc. )
	- just checkout additional branches off of the empty main branch at first
	    - The idea here is that the starter code branch should have no code/changes except ones relevant to that lesson. No other code or files should be present. Ideally, none of these branches are even aware of any other files in the repository. We want their histories to be unrelated so users can freely update one of the lessons from their copy of the template repository without affecting anything else.
- After empty starter branches are created, **for each lesson**:
	- checkout the branch for the starter code (01_begin_lesson_name) and add the starter code. 
	- make a commmit
	- checkout a solution branch from the starter branch (01_example_solution) and add solution code (+comments) there
	- move on to next lesson
- After all lessons have starter code and solution code branches, switch back to main: `git checkout main`
- Add a README.md file and include phase objectives and a table including the names of lessons and columns for links to the videos/starter/solution/notes 

## Setting up the Template Repository on GitHub
- Create a new repository on GitHub
- copy the code for pushing a repository from your local machine
- from your local repository's working directory (make sure you're on the main branch!) run the terminal commands pasted from GitHub
- checkout each of your starter and solution branches and push them up to the remote one at a time
- visit the settings page for the repository and check the checkbox beside Template Repository
- After all lessons and solutions have been added to the template repository:
	- go to the repository's page on GitHub
	- examine the branches here and confirm that you've pushed up all the branches you created on your machine
	- click on the green "Use this template" button
	- give your new repository a name
	- make sure to check the box labeled "Include all branches"
	- click the green button: "Create repository from template" 
	
## Working with a repository created from the template
- Clone your newly created instance of the template to your machine
- From the repo directory on your machine, checkout the starter code for lesson 1: `git checkout 01_begin_etc`
- checkout the main branch: `git checkout main`
	- merge lesson 1's starter code into main: `git merge 01_begin_etc --allow-unrelated-histories`
	- the allow unrelated histories flag is required here because there will be commits on the lesson branches that aren't in order and don't fit with the main commit history.
	- update main with the starter code: `git push`