LoginSignup
114

More than 5 years have passed since last update.

【簡単】GithubでWebサイトを公開する2つの方法

Last updated at Posted at 2016-01-12

はじめに

githubでWebサイトを公開したのでその手順をまとめてみました。
2つの方法があるので2つとも紹介します。
1つはユーザー(グループ)ページを作る方法・もう1つはリポジトリのページを作る方法です。
実際に僕は自分のポートフォリオサイトをgithubで公開しています。
※ 現在は個人VPSで公開しています。

参考リンク

英語ですが公式サイトは絶対なので見るのをおすすめします。
https://pages.github.com/

注意

githubでは動的なサイト(データベースとやりとりのあるサイト)は公開することができないらしいです。あとコードはオープンソースでなければなりません。

ユーザー(グループ)ページを作成する

新しいリポジトリを作成

まずはgithub上でリポジトリを作成しましょう。そのときにリポジトリの名前をユーザーネーム.github.ioにします。

作成したリポジトリをクローン

次に作成したリポジトリをクローンします。usernameの部分は自分のユーザーネームを入力しましょう。

$ git clone https://github.com/username/username.github.io

index.htmlに"Hello World"と記述

$ cd username.github.io
$ echo "Hello World" > index.html

プッシュ

$ git add --all
$ git commit -m "Initial commit"
$ git push -u origin master

完成

ブラウザを起動して、http://username.github.io にアクセスしてみましょう。

リポジトリごとのページを作成する

新しいリポジトリを作成

なんでもいいのでgithub上で新しいリポジトリをつくりましょう
ここではsampleというリポジトリを作成します。

作成したリポジトリをクローン

ユーザーページのときと同様に作成したリポジトリをクローンします。usernameの部分は自分のユーザーネームを入力しましょう。

$ git clone https://github.com/username/sample

gh-pagesというブランチに切り替える

$ cd sample
$ git checkout --orphan gh-pages
$ echo "Hello World" > index.html

プッシュ

$ git add --all
$ git commit -m "Initial commit"
$ git push -u origin gh-pages

完成

ブラウザを起動して、http://username.github.io/sample にアクセスしてみましょう。

まとめ

githubにwebサイトを簡単に公開できるのでおすすめです。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
114