redev

technical miscellaneous memorandum

GitHubリポジトリ作成とファイル追加

ここを参考に進める。
qiita.com

先ずは新規リポジトリの作成。
github.com
何となくPublicに抵抗が有ったのでPrivateで作成。
Add a README fileにチェック入れておく。

作成後、リポジトリをクローンする

$ git clone https://github.com/[username]/[repositoryname].git
Cloning into '[repositoryname]'...
Username for 'https://github.com': [username]
Password for 'https://[username]@github.com': 
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/[username]/[repositoryname].git/'

エラーが出る。どうもパスワード認証は廃止されたっぽい。
以下でPersonal Access Tokenを作成する。
https://github.com/settings/tokens

そして、前述のPasswordを要求される箇所でトークンをペーストすると、クローンが成功する。
しかし、毎回このクソ長いトークンを打つのは面倒なので、保存しておく。

$ git config --global credential.helper store

平文だがこれで ~/.git-credentials に保存される。


次に、ここの流れに沿ってファイルを追加してみる。
コマンドで使うgithubの使い方 - Qiita

ローカルリポジトリにファイルを追加

$ git add hello.ts

(変更した)ファイルを確認

$ git status
ブランチ main
Your branch is up to date with 'origin/main'.

コミット予定の変更点:
  (use "git restore --staged <file>..." to unstage)
	new file:   hello.ts

コミットする

$ git commit -m "first commit of practice"
[main e633de5] first commit of practice
 1 file changed, 2 insertions(+)
 create mode 100644 hello.ts

リモートリポジトリにプッシュ

$ git push origin master
error: src refspec master does not match any
error: failed to push some refs to 'https://github.com/[username]/[repositoryname].git'

エラーが出た。

deepblue-ts.co.jp
ここに依ると、ブランチとやらがmasterでなくmainであるのが原因ぽい。
確かに、git status で「ブランチ main」と書かれている…。
ブランチ名を確認すると、

$ git branch
* main

mainと出てる。
改めてプッシュする。

$ git push origin main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 12 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 336 bytes | 336.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/[username]/[repositoryname].git
   8f4aa79..e633de5  main -> main