git コマンドメモ
gitの基礎的な使い方メモ.
以下はすべて作業用ディレクトリで行う.
初期設定からローカルリポジトリまで
初期設定
# 初期化(.gitが生成される) $ git init # 名前とメールアドレスを設定 $ git config --global user.name "Your Name" $ git config --global user.email "you@example.com"
インデックス → ローカルリポジトリ
# インデックスにあるファイルをローカルリポジトリへ $ git commit -m "first commit"
『-m "コミットメッセージ"』でメッセージ入力画面をスキップできる.
ファイルの管理状態の表示
$ git status
.gitignore
.gitignoreというファイルに無視したいファイルのファイル名を書き込めば,管理の対象外となる.
上記のgit statusで反映を確認できる.
リモートリポジトリ関連
登録リモート一覧表示
$ git remote origin
-vオプション
$ git remote -v origin git@github.com:<username>/<repo-name>.git(fetch) origin git@github.com:<username>/<repo-name>.git(push)
FetchURLとPushURLも同時に表示.
リポジトリのURLを任意の名前と紐付ける
$ git remote add <name> <url>
使用例
$ git remote add heroku https://git.heroku.com/アプリ名.git $ git add . $ git commit -m "first commit" $ git push heroku master
変数に代入するようなイメージ?
リポジトリからリモートURLを削除
$ git remote rm origin