LoginSignup
2
2

More than 5 years have passed since last update.

初心者ならでは、github登録する

Last updated at Posted at 2015-08-26

<作業目的>
・作業端末「Mac」からgitコマンドにて対象ファイルをgithubに登録し、みんなに公開する


<前提条件>
・githubのアカウントを登録(取得)しておく。


<作業手順>
1. macにbrewを使用してgitインストール

$ brew install git

  1. macのgitにユーザ登録

    $ git config --global user.name "ユーザ"
    $ git config --global user.email "メールアドレス"

  2. その他設定(任意でどうぞ) 出力カラーリング、gitコマンドのエイリアス設定

    $ git config --global color.ui auto
    $ git config --global alias.co checkout

  3. ローカルリポジトリ作成(任意のディレクトリ配下に:例github)

    $ git init
    Initialized empty Git repository in /〜任意〜/github/.git/

  4. 今回の対象ファイルをコミット

    対象ファイルを、上述手順で作成された「github」ディレクトリに配置。

  5. コピー後のステータス確認

    $ 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)

  6. インデックスに登録

    $ git add 対象ファイル

  7. 登録後のステータス確認

    $ git status

    On branch master
    Initial commit
    Changes to be committed:
    (use "git rm --cached ..." to unstage)
    new file: 対象ファイル

  8. インデックスのファイルをコミット

    $ git commit -m "first commit"

    [master (root-commit) cbb5a29] first commit
    1 file changed, 45 insertions(+)
    create mode 100644 対象ファイル

  9. コミット後のステータス確認

    $ git status
    On branch master
    nothing to commit, working directory clean

  10. コミット後のログ確認

    $ git log

    commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ※羅列
    Author: "アカウント" <"メールアドレス">
    Date: Wed Aug 26 02:01:26 2015 +0900
    first commit

  11. githubに接続できるように、mac上でssh-keyの作成

    $ ssh-keygen

    いろいろ聞かれるが、全て空白エンターを入力

  12. ssh-keyの作成確認  ※何も指示しなければ(空白エンター)、「~/.ssh/」配下にできます

    ls -l ~/.ssh/
    id_rsa
    id_rsa.pub →こちらを「github」に登録

  13. 「github」にログインし、GUIにて「id_rsa.pub」を「github」に登録。

    ユーザの「setting」を押下
    「SSH key」を選択。
    「add SSH key」を押下し、「title」と「key」を入力。
      ・title : 自分が忘れないように、任意で入力
      ・key : id_rsa.pubを開いて、内容をコピーして貼り付け
    「Add key」を押下

  14. 「github」にて新規のリモートレポジトリを作成

    「new repository」に選択
    「Repository name」を任意で入力し、「Public」にチェックを入れ、「create repository」を押下

  15. リモートレポジトリのURLをローカルに登録

    $ git remote add origin git@github.com:"githubアカウント名"/xxxxx.git

    →作成したリモートレポジトリが「xxxxx.git」となります。

  16. リモートレポジトリに登録(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.
  17. これにて完了。お疲れ様でした。

2
2
0

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
2
2