infoMore than 3 years have passed since last update.
GitHub入門
Last updated at Posted at 2018-06-26
gitの設定
-
git config --global user.email [mail address]
でGitHubに登録しているメールアドレスを入力(--globalをつけるとPCで保存される?)
-
git config --global user.name [username]
でGitHubのユーザーネームを入力(--globalは上記と同じ)
-
git config --list
で設定の確認(git config --unset [settings name]
で設定の削除)
-
cd hogehoge
でgitをインストールするディレクトリまで移動する
-
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の登録
リモートリポジトリの作成
- リポジトリ一覧にある"New repository"から新規リポジトリを作成
- "Repository name"・"Description"を入力
- "Initialize this repository with a README"の項目にチェックを入れる
- "Create repository"ボタンを押して作成
リモートリポジトリの登録
- 対象リポジトリページの"Clone or download"からリポジトリのURIをコピーする
-
git remote add origin [repository URI]
でURIの登録
-
git remote -v
で確認
リモートリポジトリの編集など
-
git remote set-url [repository name] [repository url]
:URIの変更
-
git remote rm [repository name]
:削除
コミットの流れ
-
git add hogehoge
or git add --all
git commit -m "commit message"
git push [remote repository name] [branch name]
- 初回コミット時にリジェクトされた場合は
git merge --allow-unrelated-histories origin/master
を実行すると良い
ブランチ操作
ブランチ一覧表示
git branch
ブランチ作成
git branch [branch name]
ブランチ名の変更
git branch -m [old name] [new name]
ブランチ削除
git branch -d [branch name]
ブランチの切り替え
-
git branch [branch name]
ブランチのマージ
-
git merge [branch name]
-
[branch name]
はマージ内容の反映元であることに注意
ブランチ操作を見やすい形で表示する呪文
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
クローン
git clone [GitHub repository url] [local directory]
プル
-
git checkout [local branch name]
:変更をもってきたいブランチに移動
-
git pull [remote repository name] [branch name]
:どこから変更をもってくるか
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
What you can do with signing up