Skip to the content.

Git, GitHubとは? - 基本と最初のレポ

🇺🇸 English version: 01_Start_EN.md

このセクションでは、Git と GitHub を紹介し、最初のリポジトリの設定について説明します

概要

目次


Git とは…

バージョン管理とは?

履歴 ⌛

チームワーク 💪

バックアップ 💾

ゲームのセーブポイント 📌

バージョン管理の例

Google Docs Kintone
Google Doc Version History Kintone Record History

GitHub とは…

   
New GitHub Account New Repo

GitHub 例 - Apple

Appleが、パスワードマネージャーなどのアプリの開発者向けに、強力なパスワードを生成できるよう支援するための一連のツールとリソースを無償公開している。

github.com/apple/password-manager-resources

アップル、「Password Manager Resources」をオープンソースで公開 - ZDNet Japan


リポジトリの設定 - ハンズオン

ローカルでの設定

GitHub の設定

ローカルと GitHub を接続する


ローカルGitリポジトリを作成する

⚠️ 準備ガイド、準備内容 - 00_Prep.md, に記載されている手順をすでに完了していることを確認してください。

⚡ コマンドはどこで実行しますか?

  1. アクセスしやすいフォルダーに移動し、learning_git という名前のディレクトリを作成します。

    cd Documents
    mkdir learning_git
    cd learning_git
    
  2. pwd コマンドを使用して、正しい場所にいることを確認します

    pwd
       
    /Users/YourUserName/Documents/learning_git
    
  3. git init コマンドで git リポジトリを初期化します。

    git init
       
    Initialized empty Git repository in /Users/YourUserName/Documents/learning_git/.git/
    

⚡ Repository (リポジトリ) は、Repo と短縮されて呼ばれることもあります。


README.md ファイルの追加

  1. README.md ファイルを作成します。

    touch README.md
    
  2. README.md ファイルにリポジトリの説明を追加します。

    vi README.md
       
    # また
       
    code README.md
    
    # Learning JS Repo
    
    JavaScript 講義と課題のリポジトリです.
    

⚡ README.md ファイルは、ソフトウェアや git リポジトリの目的や使用方法を説明するために使用されます。


Git のステータスを確認する

git status コマンド

画像を確認すると、README.md を追跡する必要があることがわかります

git status
On branch main
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
 README.md
nothing added to commit but untracked files present (use "git add" to track)

ステージングエリアにファイルを追加

git add <file/folder>

git add README.md

現在README.mdはステージングエリアに存在します

git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md

Gitリポジトリにファイルを追加

git commit -m "message"

README.mdがリポジトリに追加されました!!

git commit -m "README file created"

git status
$ git commit -m "README file created"
[main (root-commit) 03098e7] README file created
 1 file changed, 3 insertions(+)
 create mode 100644 README.md

$ git status
On branch main
nothing to commit, working tree clean

GitHub リポジトリを作成する

リポジトリを作成する

learning_git という名前のリポジトリを作成します

Initialize this repository with a README.mdのチェックボックスは、選択を外してください

Gif_GitHub_Repo_Demo

Local Git → GitHub

repository を push しましょう! GitHub の Clone or download ボタンをクリックし、HTTPS リンクをコピーして URL を取得します

git remote add origin <link>

git remote add origin https://github.com/Your_GitHub_UserName/learning_git.git
git push -u origin main

端末からの結果

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 298 bytes | 298.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: This repository moved. Please use the new location:
remote:   https://github.com/ahandsel/learning_git.git
To https://github.com/ahandsel/learning_git.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

デバッグ

ローカルと GitHub の間で同期する最初のリポジトリを設定するときに、ログイン問題が発生する可能性があります。

  1. リモートリポジトリ設定を削除

    git remote remove origin
    
  2. 新しいパーソナルアクセストークンを作成する
    • github.com/settings/tokens/new
    • 端末から GitHub アカウントにログインするときに、GitHub パスワードの代わりにトークンを使用します
  3. もう一度試してみましょう

    git remote add origin https://github.com/Your_GitHub_UserName/learning_git.git
    git push -u origin main
    
  4. GitHub.com のリポジトリをチェックして、プッシュが機能したことを確認します。
    • https://github.com/Your_GitHub_UserName/learning_git.git

Documentation


Hands-on A が完了しました

Git を初期化する GitHub を設定する ローカルリポジトリを作成してプッシュする
git init
git remote add origin
github.com/new git status
git commit -m

Git の基本的なコマンドの概要

Git での変更の保存方法

スペース間でアイテムを転送する2つのコマンドがあります:

ファイル、フォルダの変更が保存される3つのスペースがあります:

01_Start_Git_Stages

   
  [ working directory ✍️ ]
  ↘️ git add 📥 ↘️
  [ staging area 📂 ]
  ↘️ git commit 💾 ↘️
  [ repository 🗄️ ]
  ↘️ git push 🔄 ↘️
  [ remote repository (GitHub) 🌐 ]

working directory, git add, staging area

   
➡️ [ working directory ✍️ ]
➡️ ↘️ git add 📥 ↘️
➡️ [ staging area 📂 ]
  ↘️ git commit 💾 ↘️
  [ repository 🗄️ ]
  ↘️ git push 🔄 ↘️
  [ remote repository (GitHub) 🌐 ]

working directory (作業ディレクトリ) ✍️

git add 📩

staging area (ステージングエリア) 📂


待って、ステージングエリア? 🤔

あなたが音楽を作っていると想像してください 🎶

ロマンチックなアルバムを作成するには 🎶

git commit, repository, git push

   
  [ working directory ✍️ ]
  ↘️ git add 📥 ↘️
  [ staging area 📂 ]
➡️ ↘️ git commit 💾 ↘️
➡️ [ repository 🗄️ ]
  ↘️ git push 🔄 ↘️
  [ remote repository (GitHub) 🌐 ]

git commit 💾

repository 🗄️

Git フォルダーの中身は何ですか? 🤔

⚡ Windows の場合、ls の代わりに dir コマンドを使用します

$ pwd
/Users/UserName/Documents/learning_git

$ ls -la
total 8
drwxr-xr-x 4 UserName staff 128 Jun 9 14:54 .
drwx------@ 20 UserName staff 640 Jun 8 16:22 ..
drwxr-xr-x 12 UserName staff 384 Jun 9 14:56 .git
-rw-r--r-- 1 UserName staff 85 Jun 9 14:54 README.md

$ cd .git

$ ls -la
total 40
drwxr-xr-x 12 UserName staff 384 Jun 9 14:56 .
drwxr-xr-x 4 UserName staff 128 Jun 9 14:54 ..
-rw-r--r-- 1 UserName staff 20 Jun 9 14:54 COMMIT_EDITMSG
-rw-r--r-- 1 UserName staff 23 Jun 9 14:54 HEAD
-rw-r--r-- 1 UserName staff 316 Jun 9 14:56 config
-rw-r--r-- 1 UserName staff 73 Jun 9 14:54 description
drwxr-xr-x 14 UserName staff 448 Jun 9 14:54 hooks
-rw-r--r-- 1 UserName staff 137 Jun 9 14:54 index
drwxr-xr-x 3 UserName staff 96 Jun 9 14:54 info
drwxr-xr-x 4 UserName staff 128 Jun 9 14:54 logs
drwxr-xr-x 7 UserName staff 224 Jun 9 14:54 objects
drwxr-xr-x 5 UserName staff 160 Jun 9 14:56 refs

git push, remote repository

   
  [ working directory ✍️ ]
  ↘️ git add 📥 ↘️
  [ staging area 📂 ]
  ↘️ git commit 💾 ↘️
  [ repository 🗄️ ]
➡️ ↘️ git push 🔄 ↘️
➡️ [ remote repository (GitHub) 🌐 ]

git push <remote> <branch> 🔄

remote repository (GitHub) 🌐

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

git remote add origin <link>

git remote

git remote --verbose

Documentation

git push?

git push <remote> <branch> 🔄

git push コマンドは、最後のプッシュまたはクローン以降に変更されていないリモートリポジトリに対してのみ機能します

ゲームの例-どうぶつの森

Documentation

ハンズオン A レビュー

Git での保存

  音楽 🎶
[ working directory ✍️ ] 個別の曲
↘️ git add 📥 ↘️  
[ staging area 📂 ] アルバム
↘️ git commit 💾 ↘️  
[ repository 🗄️ ] プレイリスト
↘️ git push 🔄 ↘️  
[ remote repository (GitHub) 🌐 ] Spotify

git remote
ローカルとリモートのリポジトリ間の接続を管理するコマンド

git push
ローカルリポジトリをリモートリポジトリにアップロードするコマンド

クイズの時間

  1. Git と GitHub はどのように関係?
    • ヒント: hub とは、活動またはネットワークの中心点です。
  2. git addgit commit のどちらを初め?
    • ヒント: commit とは、特定の行動 (結婚など) を約束することです。
  3. git push コマンドは?
    • ヒント: git push コマンドは git fetch コマンドの逆の行動を行います。
回答 1. Git と GitHub はどのように関係? * GitHub は、みんなの Git を集めた **hub** / コレクション の中心です。 * GitHub は人気のある **remote repo** オプションです 2. `git add` と `git commit` のどちらを初め? * まず、`git add` を使用して、個々の変更を集めます * そして、`git commit` を使用して、変更を包みます 3. `git push` コマンドは? * **commit** をリモートリポジトリにアップロードするには、`git push` を使用します * リポジトリの最新バージョンを取得するには、`git fetch` を使用します

次のセクション

ブランチの作成とマージ - 02_Branches.md へ 💪

講義ガイド一覧

README.md ⚙️