LoginSignup
21

More than 5 years have passed since last update.

GitHubの基本的な使い方メモ

Last updated at Posted at 2015-06-16

0.前提

gitはインストール済み、GitHubアカウント登録済み

1. GitHubにリポジトリの作成

  • webページで作成

    Repositries タブの Newボタンで作成画面が開く
    Kobito.3QZROQ.png

    Repository name ,Description, Public/Private の選択(無料プランはPublicのみ), initialize this repository with a READMEのチェックボックス はON(READMEファイルの作成)で、Create repository

2. ローカルにコーピー = クローンする

作成したいディレクトリにcd した後
git clone https://github.com/XXXXX/XXXX.git

3. .gitignoreの作成

ローカルリポジトリのディレクトリ直下に.gitignoreを作成して、バージョン管理対象外のファイルを記述。
ex).logファイルは管理対象外とする場合

.gitignore
*.log

4. git設定ファイルgitconfigの設定

(1) git設定ファイルの場所

  • 1 /etc/gitconfig 確認コマンド: git config --system -l
  • 2 ~/.gitconfig 確認コマンドgit config --global -l
  • 3 ローカルリポジトリ/.git/config git config -l *1,2,3の順番で読み込まれて同一の設定値については後で読み込まれた値で上書きされる

(2) git設定ファイルの変更

ex) ユーザ名、メールアドレスを global に設定する

git config --global user.name "Your name"
git config --global user.email "Your email"

5. ステージングエリアに移動 (git add)

(1) ステージングにadd

git add ファイル名,ディレクトリ名等

(2) addの取り消し

#ファイル単位で個別に取り消し
git rm -r --cached [file_path]
#add自体を取り消し
git reset HEAD

6. ファイルの状態確認 (git status)

git status

7. ローカルリポジトリへのコミット (git commit)

(1) コミット

git commit -m "コメント"

(2) 確認

#status確認
git status
#コミットログ確認
git log

(3) コミットを取り消したい場合やコミット漏れ対応の整理

#直前のコミット取り消し 
git reset --soft HEAD^
#n個前のコミット取り消し
git reset --soft HEAD~{n}
#直前のコミットに上書き
git commit --amend

8. pushしてGitHubに反映させる(git push)

git push リモート名 ブランチ名
ex)
git push origin master

9. GitHubのリポジトリから最新の状態を取得する

git pull リモート名 ブランチ名

10 SSHkeyの登録

(1) ローカルでSSHKey作成

ssh-keygen -t rsa -C "youremail"

Enter file in which to save the key (~/.ssh/id_rsa):
→Enterキー
Enter passphrase (empty for no passphrase):
→パスワード登録

(2) GitHubのwebページにアクセスし、設定 → Add SSH Key

Kobito.gHxDXU.png

(3) SSH Key の登録

Title : 適当に設定
Key : 以下の子アンドでkeyの内容を確認してコピペ

cat ~/.ssh/id_rsa.pub 

(4) GitHub認証確認

ssh -T git@github.com

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
21