<作業目的>
・作業端末「Mac」からgitコマンドにて対象ファイルをgithubに登録し、みんなに公開する
<前提条件>
・githubのアカウントを登録(取得)しておく。
<作業手順>
1. macにbrewを使用してgitインストール
$ brew install git
macのgitにユーザ登録
$ git config --global user.name "ユーザ"
$ git config --global user.email "メールアドレス"
その他設定(任意でどうぞ) 出力カラーリング、gitコマンドのエイリアス設定
$ git config --global color.ui auto
$ git config --global alias.co checkout
ローカルリポジトリ作成(任意のディレクトリ配下に:例github)
$ git init
Initialized empty Git repository in /〜任意〜/github/.git/
今回の対象ファイルをコミット
対象ファイルを、上述手順で作成された「github」ディレクトリに配置。
コピー後のステータス確認
$ git status
On branch master
Initial commit
Untracked files:
(use "git add ..." to include in what will be committed
対象ファイル
nothing added to commit but untracked files present (use "git add" to track)インデックスに登録
$ git add 対象ファイル
登録後のステータス確認
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: 対象ファイルインデックスのファイルをコミット
$ git commit -m "first commit"
[master (root-commit) cbb5a29] first commit
1 file changed, 45 insertions(+)
create mode 100644 対象ファイルコミット後のステータス確認
$ git status
On branch master
nothing to commit, working directory clean
コミット後のログ確認
$ git log
commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ※羅列
Author: "アカウント" <"メールアドレス">
Date: Wed Aug 26 02:01:26 2015 +0900
first commitgithubに接続できるように、mac上でssh-keyの作成
$ ssh-keygen
いろいろ聞かれるが、全て空白エンターを入力ssh-keyの作成確認 ※何も指示しなければ(空白エンター)、「~/.ssh/」配下にできます
ls -l ~/.ssh/
id_rsa
id_rsa.pub →こちらを「github」に登録
「github」にログインし、GUIにて「id_rsa.pub」を「github」に登録。
ユーザの「setting」を押下
「SSH key」を選択。
「add SSH key」を押下し、「title」と「key」を入力。
・title : 自分が忘れないように、任意で入力
・key : id_rsa.pubを開いて、内容をコピーして貼り付け
「Add key」を押下
「github」にて新規のリモートレポジトリを作成
「new repository」に選択
「Repository name」を任意で入力し、「Public」にチェックを入れ、「create repository」を押下
リモートレポジトリのURLをローカルに登録
$ git remote add origin git@github.com:"githubアカウント名"/xxxxx.git
→作成したリモートレポジトリが「xxxxx.git」となります。-
リモートレポジトリに登録(push)
$ git push -u origin master
The authenticity of host 'github.com (192.30.252.130)' can't be established.
RSA key fingerprint is "xx:xx:xx(省略)"
Are you sure you want to continue connecting (yes/no)? →yesを入力
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 780 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:"githubのアカウント名"/xxxx.git- [new branch] master -> master Branch master set up to track remote branch master from origin.
これにて完了。お疲れ様でした。