gitの使い方 Github上にリモートレポジトリを作って連携する
の続編です。まずGithubにSign inします。できましたか?

この画面で左上の緑の枠取りの“New”をクリックします。下図の“Create a new repository”で必須の情報の“Repository name”にhello_world(一例),今回は”Public”を選んで、一番下の“Create repository”をクリック。

すると。

この画面には重要な情報が含まれています。テキストを抜き出しておきましょう。
新規のレポジトリをこれから作るのだと:
echo "# hello_world" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/alt-doc-nao/hello_world.git
git push -u origin main
既存のレポジトリをpushするのであれば、
git remote add origin https://github.com/alt-doc-nao/hello_world.git
git branch -M main
git push -u origin main
となります。前回の記事でローカルなレポジトリは作成済みなので、後者のコマンドを入れますが、デフォルトのbranchは確認済みのようにmainなので、二行目のgit branch -M mainは不要です。やってみましょう。

上図で“git push -u origin main”したタイミングで、

が出てきましたが、間違えず先ほどSign Inした方のアカウントを選びます。

ここで”Continue”をクリック。すると“git push….”が無事完了します。
jakeb@Orbit-11 MINGW64 ~/OneDrive/Desktop/bash for development cycle (main)
$ git status
On branch main
nothing to commit, working tree clean
jakeb@Orbit-11 MINGW64 ~/OneDrive/Desktop/bash for development cycle (main)
$ git remote -v
origin https://github.com/alt-doc-nao/hello_world.git (fetch)
origin https://github.com/alt-doc-nao/hello_world.git (push)
jakeb@Orbit-11 MINGW64 ~/OneDrive/Desktop/bash for development cycle (main)
$ git push -u origin main
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 550 bytes | 275.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/alt-doc-nao/hello_world.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
jakeb@Orbit-11 MINGW64 ~/OneDrive/Desktop/bash for development cycle (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
“git push …”前後で“git status”の結果が異なっていることに注意しましょう。
このタイミングでWebからレポジトリを見に行くと、

リモートレポジトリの中身が出来ていることがわかります。2回”Commit”したので、

それぞれの“Commit”が反映されています。

これが最初のcommit->2回目のcommit間の差分です。
こうしてできたリモートレポジトリは”Public(公開)”で作成しましたから、誰でも取ってくることができます。その方法は、

“Code”をクリックして得られるプルダウンメニュー(上図)からurlをコピーして、それを使って”git clone”すれば可能です。確認のために、やってみましょう。

別のフォルダー内部で”Git Bash”を起動して、”git clone https://github.com/alt-doc-nao/hello_world.git”を実行すればできます。
コメント