LoginSignup
0
0

More than 1 year has passed since last update.

gitのコミットからプッシュまでのコマンドの流れ

Last updated at Posted at 2021-08-04

概要

gitのコミットからGitHubへのプッシュまでの流れを簡単にまとめます。

git branch

まずは、コミットする前に現在のブランチを確認します。

% git branch
  feature
* master

git checkout ブランチ名

現在のブランチがコミットしたいブランチでない場合、ブランチを変更します。

% git checkout feature
Switched to branch 'feature'

% git branch
* feature
  master

git diff

ステージングにある変更ファイルの差分を確認します。

% git diff
diff --git a/routes/web.php b/routes/web.php
index bc07a90..4e62548 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -25,6 +25,11 @@ Route::get('/', function () {
     ]);
 })->name('home');

+Route::post('/quiz/{quiz}/answer/confirm', [QuizController::class, 'answerConfirm'])->where('quiz', '[0-9]*')->name('quiz.answer.conf');
+
Route::post('/quiz/{quiz}/answer/result', [QuizController::class, 'answerResult'])->where('quiz', '[0-9]*')->name('quiz.answer.result');

Route::get('/ranking/correct', [HomeController::class, 'rankingCorrect'])->name('ranking.correct');

※左に 「+」 がある行が追加したコードになります。またコードを削除した場合は、「-」となります。

git add .

変更をステージングエリアに追加する。

% git add .

※出力はありません。

git status

ステージングエリアに変更したファイルが有ることを確認します。

% git status
On branch feature
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   routes/web.php

※ 「Changes to be committed:」内にあるファイルはコミットできるファイルになります。

git commit -m ‘コメント内容

コミットコメントを記載してコミットします。

% git commit -m 'ルートの追加'
[feature cdf2899] ルートの追加
 1 file changed, 2 insertions(+)

git log

コミットログを表示してコミットできていることを確認します。

% git log
commit cdf28999264f4a120a909f3c80fb9c8510db665a (HEAD -> feature)
Author: hirokimituya <hiromitu819@yahoo.co.jp>
Date:   Wed Aug 4 19:42:39 2021 +0900

    ルートの追加

※コミットログの表示をやめるには、qを入力します。

git push origin ブランチ名

GitHubにコミット内容をプッシュします。

% git push origin feature
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 373 bytes | 373.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To github.com:hirokimituya/jetstream-doc.git
   2b5159d..cdf2899  feature -> feature

まとめ

普段はGitHub Desktopを使用してgitコマンドを使用していませんが、たまにはgitコマンドを使ってGitHub Desktopが使えないもしものときに備えることも必要かもしれません。
以上になります。ご観覧ありがとうございました。

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