Branch publish
- Git course
- Advanced
- Lesson 46/56
- 4 min
Learn to publish from a specific branch.
Publishing with a branch
GitHub Pages publishes the files of your site from a specific branch. By convention the branch named gh-pages is used for this job. You open the publish branch and add the site files there.
git checkout -b gh-pagesThe branch being published contains the source files of the site.
The publish branch
The publish branch is where the site files live. It contains files like index.html, and each commit updates the site. The publish branch follows its own line, separate from the development branch.
git checkout -q -b gh-pages
echo "yayin" > index.html
git add index.html
git commit -q -m "site"Practice Prepare the publish branch
Create temel.txt and save it quietly. Open a branch named gh-pages; there create index.html with site hazir inside, add it and save quietly. Print the file contents at the end.
Starter code
git init -q
# 1) temel.txt olustur, ekle ve sessizce kaydet
# 2) gh-pages adinda yeni bir dal ac
# 3) index.html olustur, icine site hazir yaz
# 4) dosyayi ekle ve sessizce kaydet
# 5) dosya icerigini yazdirSample solution
git init -q
echo "temel" > temel.txt
git add temel.txt
git commit -q -m "temel"
git checkout -q -b gh-pages
echo "site hazir" > index.html
git add index.html
git commit -q -m "yayin"
cat index.htmlExpected output
site hazir
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the gh-pages branch used for?
- It is a backup branch
- It is the name of the development branch
- The branch where the site files are published Correct answer
- It is used to store temporary files
Explanation: The gh-pages branch is where site files are published; the files on this branch are served on the web.
2 Open the publish branch
git checkout -q -b ____
git checkout -q -b gh-pages
Explanation: By convention the gh-pages branch is used for GitHub Pages publishing.
3 Publish branch
| Term | Meaning |
|---|---|
gh-pages |
Branch reserved for publishing |
publish |
The act of going live |
site_files |
Files included in publishing |
main |
Name of the development branch |