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?

初めてローカルのソースコードをGitHubにアップロードする手順

Posted at

初めてGitHubにアップロードする手順

たまにやると忘れてしまうので備忘録的に残しておく。

目次

前提

  • ローカルにソースコードは存在している
  • GitHub上にはまだリポジトリがない

手順

1. GitHubでリポジトリを新規作成する

  1. GitHubにログイン
  2. 画面右上の「New Repository」ボタンを押す
  3. 以下を入力
    • Repository name:リポジトリ名を入力(例:my-project
    • VisibilityPublicPrivateを選択
    • (※READMEは作成しない)
  4. Create repository」をクリック

2. ローカルで操作する

ターミナルでソースコードのあるディレクトリへ移動して、以下を実行します。

# Gitリポジトリを初期化
git init

# ファイルを全てステージング
git add .

# コミット
git commit -m "first commit"

# リモートリポジトリを登録
git remote add origin https://github.com/ユーザー名/リポジトリ名.git

# mainブランチにプッシュ
git push -u origin main

注意:GitHub上のリポジトリは空のまま作成しておきましょう(READMEなどを作らない)。
もしリモートに何かファイルがあると、pushのときにエラーが発生するため。

3. まとめ

以下の5つの手順を実行することで
ローカルのソースコードをGitHubにアップロードできる。

git init → git add . → git commit → git remote add origin → git push
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?