4. こんどはGitHub上にパブリックリポジトリを作ってプログラムのソースコードを共有してみよう。
まずはリモートレポジトリ側を用意。github.comへサインインしてpublic repositoryを作る。

ここで”Create repository”。

ここでhttpsのurlをcopyないしメモしておく。リモートリポジトリ側の用意はこれで済みました。
C++ Builder CEを起動して、前回と同様にVCLプログラムを新規作成します。フォーム上にTButtonとTMemoを置きます。その状態が、

上図ですが、Form1上のMemo1を選択して、左下にあるオプジェクトインスペクタのAlignを下図のようにalBottomにします。すると下図のようになります。

Memo1の配置が”左”、”下”、”右”の3方向がフォームの境界に張り付いた感じになります。これでは狭すぎるので、Memo1の上側の中央のハンドルを上方にドラッグします。またButton1位置も適宜変更して、

こんな感じでオケです。”Button1″というのもデフォルト過ぎるので、適宜変更しますかね。それにはButton1をクリックして、プロパティーのCaptionを変更すればよいです。”Say”とかでもいいですかね。

さて、Form1上でButton1をダブルクリックして、
Memo1->Lines->Add("こんにちは、世界");
と入力しましょう。追加したコードは、
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Add("こんにちは、世界");
}
です。ここで一旦セーブしましょうか?その後”F9″を押します。”Say”を押すと、

となります。あー、初期状態のMemo1が邪魔ですかね?それならば、Form1のコンストラクタに次のコードを追加しましょう。
Memo1->Lines->Clear();
ここまででUnit1.cppは、
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Memo1->Lines->Clear() ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Memo1->Lines->Add("こんにちは、世界");
}
//---------------------------------------------------------------------------
一応期待通りに動いているようなので、先ほどNAS上に作ったリモートリポジトリにgit pushしてみましょうか?それには前記事のように、まずバージョン管理への追加で、

インポート。
ここで前回と同様にエクスプローラーに抜けて、Bash for Git hereを起動して、push -u origin mainすると、

で、

jakeb@Orbit-11 MINGW64 ~/OneDrive/Documents/Embarcadero/Studio/Projects/mem-hello-world (main)
$ git status
On branch main
nothing to commit, working tree clean
jakeb@Orbit-11 MINGW64 ~/OneDrive/Documents/Embarcadero/Studio/Projects/mem-hello-world (main)
$ git push -u origin main
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 12 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 6.27 KiB | 3.14 MiB/s, done.
Total 8 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/alt-doc-nao/some-new-repo.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
jakeb@Orbit-11 MINGW64 ~/OneDrive/Documents/Embarcadero/Studio/Projects/mem-hello-world (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
今度はパブリックなレポジトリなので、誰でもレポジトリを読む出すことができます。そのurlは、
です。試してみてください。
コメント
[…] 前回でgit pushしたリモートレポジトリをIDEから扱ってみようかね。urlは、 […]