0
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にコミットする備忘録

Last updated at Posted at 2025-09-21

ソースをGitにcommitするにあたって右往左往したので、手順をまとめておきます。
GitHubのアカウントは作成済みとします。

記事の作成日:2025/09/21,環境:Mac OS

初期設定

◾️Gitにユーザー情報を登録する

→コミットした人が誰かわかるようにするため

Terminalで以下を実行。

git config --global user.name "自分の名前"
git config --global user.email "GitHub登録メールアドレス"

反映されたかどうかは以下のコマンドで確認できる。

git status --list

リポジトリの作成

GitHubで新しいリポジトリを作る(Private推奨)

URLをコピーしておく(例: https://github.com/ユーザー名/リポジトリ名.git)

Git操作

◾️Gitの初期化

Terminalにて、リポジトリにコミットしたいフォルダパス内に移動
cd 〇〇(コミットしたいフォルダ)

Gitの初期化

git init

→ .git/ フォルダができて、ここから「このフォルダをGitで管理します!」という状態になる。

◾️無視するファイルを設定

不要なファイルがGitHubに上がらないように .gitignore を作る。
※APIのキーなど、セキュリティ上gitにあげないほうが良いファイルを設定する。

nano .gitignore

◾️ファイルをステージング

「どのファイルを次のコミットに含めるか」を選ぶ。
全部入れる場合は

git add.

◾️コミット

選んだファイルをローカルGitにスナップショットとして保存する。

git commit -m "Initial commit: プロジェクトを追加"

→ この段階ではまだローカルだけに保存されていて、GitHubには送られてない。

◾️プッシュ

ローカルのコミットをGitHubに送信

git push -u origin main

※-uは次回コミット時もここにコミットする、と設定できる

branchを分けている場合

git push -u origin branch

自分がどこにいるかわからなくなったら

git branch

main
*branch
となっていればOK

◾️その他

#(任意)タグをつけて履歴を残す 特定の状態をマークしておくと便利。
git tag baseline-legacy
git push --tags

→タグをつけることで履歴をわかりやすくできる。
タグについてはこちらのサイトがわかりやすかったので参考元として記載します。
https://tec.tecotec.co.jp/entry/2022/12/14/000000

0
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
0
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?