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 & GitHub 初期設定〜pushまで(自分用)

1
Posted at

🎯 目的

新しいプロジェクトを
GitHub にアップロードするまでを最短で再現する


🧭 全体の流れ

  1. Git初期設定(初回のみ)
  2. GitHubでリポジトリ作成
  3. ローカルでGit初期化
  4. GitHubと接続
  5. push

① Git初期設定(※最初だけ)

git config --global user.name "ユーザー名"  
git config --global user.email "メールアドレス"  
git config --global init.defaultbranch main

確認👇

git config --list

② GitHubでリポジトリ作成

  • 「New repository」
  • 名前入力
  • READMEはチェックしない(デフォチェック無し)
  • Public / Privateは用途に応じて
  • 👉 リポジトリURLをコピー
https://github.com/ユーザー名/リポジトリ名.git

③ ローカルでGit初期化

cd プロジェクトフォルダ
git init

④ ファイルを登録してコミット

git add .
git commit -m "first commit"

⑤ GitHubと接続

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

確認👇

git remote -v

⑥ push(アップロード)

git branch -M main  
git push -u origin main  

🔐 認証について(重要)

  • パスワードは使えない
  • 初回push時にログイン画面が出る
  • GitHubアカウントでログインすればOK
    ※ Windowsなら credential manager に保存される

👍 HTTPSとSSHの使い分け

今回はHTTPSでOK

HTTPS:

  • 設定が簡単
  • 自動ログインで楽
  • 個人ならこちらで十分

SSH

  • 複数PCで開発
  • Gitをガチ運用
  • チームプロジェクト

⚠️ ハマりポイント

❌ READMEをGitHub側で作る

→ 初回pushでコンフリクト


❌ master / main問題

→ git branch -M main で統一


❌ remote設定ミス

git remote -v

で確認


🧹 .gitignore(最低限)

Python系なら👇

  • __pycache__/
  • *.pyc
  • .env
  • .DS_Store

🧠 自分用メモ

  • 迷ったらHTTPSでOK
  • Publicで作ってもPrivateに変更可能
  • リポジトリ削除も簡単

🚀 最短コマンドまとめ(コピペ用)

cd プロジェクトフォルダ  
git init  
git add .  
git commit -m "first commit"  
git remote add origin https://github.com/ユーザー名/リポジトリ名.git  
git branch -M main  
git push -u origin main  

✨ ひとこと

Gitは「最初だけちょっと面倒、あとは超便利」な道具。
未来の自分が“あの時まとめてくれてありがとう…”ってなるやつ。


🔧 追加カスタム案(余力あれば)

  • プロジェクト別の .gitignore
  • READMEテンプレ
  • ブランチ戦略(main / develop)
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?