LoginSignup
1
3

More than 3 years have passed since last update.

GitHub入門

Last updated at Posted at 2018-06-26

 gitの設定

  1. git config --global user.email [mail address]でGitHubに登録しているメールアドレスを入力(--globalをつけるとPCで保存される?)
  2. git config --global user.name [username]でGitHubのユーザーネームを入力(--globalは上記と同じ)
  3. git config --listで設定の確認(git config --unset [settings name]で設定の削除)
  4. cd hogehogeでgitをインストールするディレクトリまで移動する
  5. git initでgitリポジトリとして初期化
  • ".gitignore"ファイルにgit管理したくないファイルを記述する
  • "~/.gitconfig"にusernameとemailが記述されてるか見る
  • ディレクトリごとに設定した場合は"./git/config"

ファイルをローカルリポジトリへコミット

ステージングエリアへ移動

  • git add hogehoge :特定のファイルを移動
  • git add --all :コミットされていないすべてのファイルを移動
  • git status :状態を確認

リポジトリへコミット

  • git commit :コミットを行うが、コミットメッセージの入力を求められる
  • git commit -m "hogehoge" :メッセージ付きでコミットを行う
  • git log :変更履歴の確認

GitHubの登録

リモートリポジトリの作成

  1. リポジトリ一覧にある"New repository"から新規リポジトリを作成
  2. "Repository name"・"Description"を入力
  3. "Initialize this repository with a README"の項目にチェックを入れる
  4. "Create repository"ボタンを押して作成

リモートリポジトリの登録

  1. 対象リポジトリページの"Clone or download"からリポジトリのURIをコピーする
  2. git remote add origin [repository URI]でURIの登録
  3. git remote -vで確認

リモートリポジトリの編集など

  • git remote set-url [repository name] [repository url] :URIの変更
  • git remote rm [repository name] :削除

コミットの流れ

  1. git add hogehoge or git add --all
  2. git commit -m "commit message"
  3. git push [remote repository name] [branch name]
  • 初回コミット時にリジェクトされた場合はgit merge --allow-unrelated-histories origin/masterを実行すると良い

ブランチ操作

ブランチ一覧表示

  1. git branch

ブランチ作成

  1. git branch [branch name]

ブランチ名の変更

  1. git branch -m [old name] [new name]

ブランチ削除

  1. git branch -d [branch name]

ブランチの切り替え

  1. git branch [branch name]
    • [branch name]は異動先のブランチ

ブランチのマージ

  1. git merge [branch name]
    • [branch name]はマージ内容の反映元であることに注意

ブランチ操作を見やすい形で表示する呪文

  1. git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- *%an%C(reset)%C(bold yellow)%d%C(reset)' --all

クローン

  1. git clone [GitHub repository url] [local directory]

プル

  1. git checkout [local branch name] :変更をもってきたいブランチに移動
  2. git pull [remote repository name] [branch name] :どこから変更をもってくるか
1
3
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
1
3