最重要!開発用ブランチの変更をリモートのmainに反映する
①自分のいるブランチを確認
git branch
②プルリクエストを作成
git add .
git commit -m "fix"
git push origin dev
④github上からマージを実行。devのリモートブランチは開発を続けるなら残しておいていい
⑤リモートの変更をローカルのmainにも反映させる
git checkout main
git pull origin main --rebase または git pull origin main
アプリ作成からgithubとの連携までの流れ
①ターミナルで特定のディレクトリにアプリを作成
以下例
cd Downloads
npx create-next-app 名前
cd 名前
②githubを開いてください
「new」ボタンをタップし、リポジトリを作成
③「or create a new repository on the command line」のコードをコピーして、先ほど作成したディレクトリで貼り付け実行
④githubに戻ってファイルなどが追加されていれば成功している
クローンからpull requestまでの一連の手順
リポジトリをクローンする。
git clone リポジトリ名
リポジトリに移動
cd リポジトリ名
開発用ブランチを作成
git checkout -b develop
ステージングに移す
git add .
コミットする
git commit -m "メッセージ"
任意のブランチにpushする(stage,mainなど)
git push origin プッシュしたいブランチ名
メインブランチに移動
git checkout main
ローカルのmain(master)ブランチをリモートの最新に更新する
git pull origin main
作成した開発用ブランチを削除する
git branch -d ブランチ名
チームのアカウントにリポジトリを追加する方法
①githubを開いてください
「new」ボタンをタップする。「choose an owner」でチームを選択し、リポジトリを作成。
※このとき、基本privateに設定しておいた方がよい
②「or create a new repository on the command line」のコードをコピーして、先ほど作成したディレクトリで貼り付け実行
③githubに戻ってファイルなどが追加されていれば成功している。あとは設定から権限を付与する。
Github CLI
インストール
brew install gh
以下のコマンドで連携
gh auth login
以下goのtodoアプリの作成を例にリポジトリ作成の手順
gh repo create
? What would you like to do? Create a new repository on GitHub from scratch
? Repository name go_todo_app
? Repository owner t38miwa
? Description TODO Web Application with AUTH by Go.
? Visibility Private
? Would you like to add a README file? Yes
? Would you like to add a .gitignore? Yes
? Choose a .gitignore template Go
? Would you like to add a license? Yes
? Choose a license MIT License
? This will create "go_todo_app" as a private repository on GitHub. Continue? Yes
✓ Created repository t38miwa/go_todo_app on GitHub
https://github.com/t38miwa/go_todo_app
? Clone the new repository locally? Yes
Cloning into 'go_todo_app'...
作成したディレクトリに移動し、以下のコマンドを入力すればブラウザから確認可能
gh browse
400番台エラーの解決法
400番台はクライアントからサーバーへのリクエストでエラーが起きている。直接的な原因がわからないため、AIに聞いてもずれた答えが返ってくることがある。今回発生したエラーは以下のようなもの。
Enumerating objects: 31, done.
Counting objects: 100% (31/31), done.
Delta compression using up to 8 threads
Compressing objects: 100% (28/28), done.
error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400
send-pack: unexpected disconnect while reading sideband packet
Writing objects: 100% (28/28), 9.97 MiB | 12.45 MiB/s, done.
Total 28 (delta 16), reused 0 (delta 0), pack-reused 0
fatal: the remote end hung up unexpectedly
Everything up-to-date
原因
http.postBufferの容量が上限の2MBを上回っていたことが原因だった。以下のコマンドで容量を変更できる。
git config http.postBuffer 500M
だがそもそも上限を上回らないことが重要。
.gitignoreでgithubにpushするべきで無いファイルやフォルダを指定して容量を減らそう。
他の400番台エラー
今回こちらの原因も疑った。だが、テスト用に作成した自分のgithubアカウントリポジトリでも同様のエラーが発生したのでこれでは無いとわかった。でも気をつけよう。
会社のリポジトリにプッシュしたとき「Couldn't connect to server」のエラーが出たらまずはVPNを確認しろ