LoginSignup
8
4

More than 5 years have passed since last update.

ローカルプロジェクトをGitHubにアップロード

Posted at

はじめに

今の自分に必要な物だけを記述.

ローカルのプロジェクトをGitHubにアップロードする方法

とりあえずコード保管のためにGitHubにアップロードする際に使用

# GitHubへアップロードしたいプロジェクトディレクトリ内へ移動
$ cd /path/to/your/project
$ git init

# 必要であれば.gitignoreを作成し、バージョン管理しないファイルやディレクトリを記載(例:*.log)
$ vim .gitignore

# プロジェクトディレクトリ内にあるファイルやディレクトリを全てコミット 
$ git add .
$ git commit -m "Initial Commit"

# リモートリポジトリの確認
$ git remote -v

# 先ほど作成したGitHubリポジトリのURLをコピー&ペーストして、リモートブランチとして設定
$ git remote add origin https://github.com/your-name/project-name.git

# 間違えてリモートリポジトリを指定してしまったらset-urlで変更
$ git remote set-url origin https://github.com/your-name/project-name.git

# ローカルのファイルをアップロード
$ git push -u origin master

ここで、アップロードできない場合はfetchとmergeをすればどうにかなることが多い.

$ git fetch
$ git merge --allow-unrelated-histories origin/master

※ 参考
ローカルのプロジェクトをGitHubにアップロードする方法
初めてGitHubリポジトリにpushしたらrejectedエラーになったときの対応メモ

8
4
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
8
4