LoginSignup
0
1

More than 3 years have passed since last update.

【学習メモ】Git、GitHubの基礎(1)

Last updated at Posted at 2020-05-17

0. 目標

Gitの基本的なワークフロー、コマンドの内容や機能を理解する

1. Gitの基本的なワークフロー

変更をコミットする流れ
1.ファイルの変更をステージングエリア(≒控え室)へ追加
2.ローカルリポジトリにcommit(委託する)
3.リモートリポジトリにpushする

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

ステージングエリア:複数ファイルを変更する際に、コミットするファイルを選択する

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

$ git add [ ファイル名 ]
$ git add. (ファイル全体を移動させる)

3.ローカルリポジトリへCommit

ステージングエリアへの追加が終わったら、Commitする

$ git commit
$ git commit -v 

すると、こんな感じでVimエディタというCommitを編集するエディタが表示される

■ ← #入力画面
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is ahead of 'origin/master' by 5 commits.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#       modified:   first.txt

入力方法は、次の通り

<Vimエディタの使い方>
①ターミナルでgit commitを入力する
②Vimエディタが立ち上がる
③半角英数字に入力を切り替える
④「i」を入力する(挿入モードになる)
⑤コミットメッセージを入力する
⑥「esc」を押す(ノーマルモードに戻る)
⑦「:wq」を入力してエンターを押す
(commitメッセージを保存してエディタを閉じる)

※Vimエディタ(⑤)の書き方のポイント
1行目:変更内容の要約
2行目:空行(空白)
3行目:変更理由(何のため?背景は?)

⑦が終わると、こんな感じの履歴が残り、元のターミナルに戻る

[master ***] ***を〜〜(変更内容)
 1 file changed, 2 insertions(+), 1 deletion(-) ※一例

<その他補足>
最初に変更する時は、「initial commit」と書くのが慣例

4.GitHubへのプッシュ

GitHubへプッシュするためには、GitHub上でリモートリポジトリを用意する必要がある

流れ

1.ブラウザでGitHubを開き「NewRepository」をクリック
2.Repository nameを設定
3.Public を選択
4.Create Repositoryを押す
5.push用のコマンドがブラウザ表示されるので、ターミナルに実行

5.の様子
git remote add origin ... (イメージ)
6.の様子
git push -u origin master ...(イメージ)

続きは明日以降投稿予定

参考
1.Railsチュートリアル Git
https://railstutorial.jp/chapters/beginning?version=5.1#sec-version_control

2.udemy講座
https://www.udemy.com/course/intro_git/learn/lecture/6449716#content

0
1
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
0
1