1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[備忘録] Gitの便利コマンド集

Posted at

Gitの便利コマンド集を備忘録として記録します。
何かの機会にお役立てください。


1. ローカルブランチ名の変更

git branch -m master main

-m は rename の意味です。これでローカルブランチ名が master から main に変わります。


2. リモートの URL を確認

git remote -v

現在のリモートリポジトリの URL を確認します。


3. ローカルの main をリモートにプッシュして upstream を設定

git push -u origin main

-u オプションで、ローカルの main ブランチとリモートの main ブランチを紐付けます。
以降は git push / git pull が簡単に使えます。


4. 古い master ブランチをリモートから削除(必要に応じて)

git push origin --delete master

リモートに残っている master ブランチを削除します。
※ 他の開発者が作業中の場合は注意してください。


5. リモートリポジトリが正しく設定されているか確認

git remote -v

origin が正しい URL を指しているか再確認します。


6. リモートリポジトリを追加(未設定の場合)

git remote add origin https://github.com/ユーザー名/リポジトリ名.git

リモートが未設定の場合は追加します。


7. main ブランチをリモートにプッシュ

git push origin main

8. 強制 push(必要に応じて)

git push origin main --force

※ リモートの履歴を上書きするため、他の人が作業している場合は慎重に行ってください。


参考

  • GitHub の「Default branch」を main に変更することも忘れずに。
  • 他の開発者にもブランチ名変更の旨を必ず伝えましょう。
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?