Git&GitHubまとめ - Paku-Soba/Svelte-example-app GitHub Wiki

Gitコマンドライン

  • git init
    • ローカルリポジトリを作成する。コマンド実行したディレクトリの配下に、「.git」ディレクトリが自動作成される。
      • この作業でGitでバージョン管理をするための準備は完了となる。
  • git add ファイルまたはディレクトリパス
    • ワークツリーで作成したファイルをステージングエリアに登録する。
      • Gitのワークツリーとは、実際に作業をしているディレクトリのことを指す。
      • ステージングエリアとは、コミットするファイルを登録する場所のことを指す。
        • git add .: カントリディレクトリ配下のすべてのファイルを追加する。
  • git commit -m "first commit"
    • ステージングエリアに登録したファイルをコミットする。
    • 「-m」オプションを付けると、コマンドラインから直接コミットメッセージを指定できる。
      • コマンドを実行するとコミットされてその結果が表示される。
  • git branch -M main
    • 作業中のブランチの名前をmainに強制変更する。
    • 「-M」オプションは、強制的にブランチ名を変更するというオプションである。
      • 現在のブランチ名が「main」以外の場合、強制的に「main」へ変更する為、コマンド実行時は注意が必要。
  • git remote add origin https://github.com/Paku-Soba/Svelte-SampleApp.git
    • リモートレポジトリにGitのコード履歴をPushするためには、リモートレポジトリをローカル環境に登録する必要がある。
    • error: origin 리모트가 이미 있습니다.
      • 今回は、GitHub Desktopを使ってリモートリポジトリをローカル上に登録した状態の為、すでに存在していると表示。
  • git push -u origin main
    • ローカルレポジトリのGitのコード履歴をリモートリポジトリへPushする。
    • 「-u」オプションは、「--set-upstream」オプションの省略形である。
      • 指定したリモートレポジトリのブランチを上流ブランチ(upstream)として設定する。
    • originPush先のリモートリポジトリの名前、mainPushするブランチ名。
      • ローカル上のmainブランチの上流ブランチにoriginのmainブランチを指定する。

Gitのコード管理の流れ

リモートリポジトリ(Github)
    ↑ push   ← ココ
ローカルリポジトリ
   ↑ commit
ステージ(インデックス)
   ↑ add
作業中のディレクトリ

GitHubリポジトリ作成からPushまでの流れ

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.

CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ echo "# Svelte-SampleApp" >> README.md

CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ git init

/Users/mac-mr9v2j001/Documents/GitHub/Svelte-SampleApp/.git/ 안의 기존 깃 저장소를 다시 초기화했습니다

CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ git add README.md

CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ git commit -m "first commit"

// コミットされて結果が表示される。
[main (최상위-커밋) e3d2410] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md 

CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ git branch -M main

CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ git remote add origin https://github.com/Paku-Soba/Svelte-SampleApp.git

error: origin 리모트가 이미 있습니다.

CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ git push -u origin main

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Paku-Soba/Svelte-SampleApp.git/'
  • git log
    • コミット履歴を確認する。
    • コマンドを実行すると新しい順に
      • 「コミットハッシュ」「ユーザー名とメールアドレス(誰がコミットしたのか)」「コミットした日時」「コミットメッセージ」が表示される。
CSAMC-FVFDM030P3YW:Svelte-SampleApp mac-mr9v2j001$ git log

commit 9cf74644213663ad8bfbbd130b67282f9fe77f5a (origin/main, origin/HEAD, main)
Author: Paku-Soba <[email protected]>
Date:   Wed Dec 20 16:39:43 2023 +0900

    [add] Create GitHub Remote repository

commit e3d241007f5fb879f298eff09400ce29d52fa64e
Author: Paku-Soba <[email protected]>
Date:   Wed Dec 20 16:32:11 2023 +0900

    first commit
  • git branch
    • コマンドを実行すると作成済みのブランチ一覧と現在使用中のブランチ確認ができる。
mac-mr9v2j001@CSAMC-FVFDM030P3YW Svelte-SampleApp % git branch
* #InstallTailwind
  CreateSvelteKit
  main

echo "# Svelte-SampleApp" >> README.md: 「# Svelte-SampleApp」をREADME.mdに出力する。

Git Hub

  • GitHub Introduction
  • About Repositories
  • Creating A NewRepository
    • ローカルで作成したプロジェクトをGitHubリポジトリにPushる。
    • GitHubリポジトリからプロジェクトを作成しPushする。
      • 今回はGitHubリポジトリからブランチを作成して環境構築対応を行う。

参考記事

Compile Information Plan

Compile Information

Try different ways to input / output information.

  • PlanA

    • Information Gathering → Understanding the Content → Summarizing Relevant Information → Implementation
  • PlanB

    • Implementation → Finding essential information → Understanding the Content → Implementation

→ In the case of PlanA, it is costly. Because information processing requires time and resources.
If there is a prerequisite knowledge of the technology, PlanB is more effective.Allowing for efficient progress in tasks.
Input and Output are necessary to understand information. For information acquisition, both PlanA and PlanB are effective. Just Try it.

【課題】 Git履歴からブランチ運用について理解すること

◾️Git履歴 GItLog

開発環境Git履歴まとめ

◾️1/25時点_開発環境Git履歴 0125_GitLog
  • CreateSvelteKitブランチ、#Install Tailwindブランチは、origin/mainブランチへマージ済み。
  • 上記の二つのブランチをorigin/mainブランチへマージ状態で#FlowbiteSvelteブランチを作成。
  • #TryThemブランチも同様。
    • daisyUI Themesの検証をまだ続けている為、origin/mainブランチへマージしていない。
    • #TryThem, #FlowbiteSvelteブランチにて、DarkModeの検証を行なっている。
◾️2/8時点_開発環境Git履歴 Git履歴

→ 現段階では技術検証実施中のブランチがメインとなる為、リポジトリの資産連携時、整理する必要有り。

◾️3/7時点_開発環境Git履歴 0307Gitlog
  • サンプルコード実装ブランチ運用について
  • #UIsampleCode ブランチで大まかなUIサンプルコード実装を進める。
    • 現段階でのブランチは、ほとんど検証状態のブランチな為
    • 複数のブランチでサンプルコードを実装するより一つのブランチでまとめて実装した方が効率的であると判断。
    • 但し、実装したコード(修正含む)は、資産管理面から部品単位でこまめにpushするようにする。
      • 部品作りを優先して進めている為、Layout(Header,Main,Footer)どうするか、考える。
      • アイコンSVG対応は、まとめて行う。 → XD開発用リンクからの対応がコストかかる場合、ライブラリ使用を検討する。
        • mainブランチへmargeする際、競合が発生することを認識しておく。
        • 競合解決等は、margeするタイミングで考える。
◾️3/15時点_開発環境Git履歴 03151850
  • #UIsampleCodeブランチにてコードリファクタリング対応を行なっている。
    • ブランチ状況は3/13時点と変わらない状況である。

3/13時点_ブランチ状況まとめ

No. ブランチ名 用途 状態 備考
1 main Defaultブランチ 最新版状態 -
2 #TryThem daisyUIライブラり検証ブランチ daisyUIのThemes検証状態 daisyUIの他の技術も検証可
3 #FlowbiteSvelte FlowbiteSvelteライブラり検証ブランチ FlowbiteSvelteのモード変換検証状態 Flowbiteも検証可
4 #PrelineUI PrelineUIライブラリ検証ブランチ PrelineUIライブラリ設定が必要な状態 ライブラリが必要であれば、使用可
5 #UIsampleCode UIサンプルコード実装ブランチ mainブランチへマージ済み状態 サンプルコード実装するブランチとして利用可
⚠️ **GitHub.com Fallback** ⚠️