LoginSignup
1
2

More than 3 years have passed since last update.

作ったプロジェクトを GitHub の新規レポジトリに

Last updated at Posted at 2020-01-05

書いたプロジェクトをGitHubに新規アップロードするフロー。いつも忘れたころに「どうやるんだっけ?」と毎度調べてしまうので、ここにもメモしておく。

1. GitHubサイトで新規レポジトリ追加

ここでは my-project-repos とする。

2. 作ったプロジェクトのディレクトリで git init
3. 必要であれば git config
$ git config user.name "my-user"
$ git config user.email "myusermail@mymail.com"
$ git config credential.helper my-cred-store
4. git リモート追加
   $ git remote add origin https://github.com/my-user/my-project-repos.git
5. git pull
$ git pull origin master
6. まだやってなければ .gitignore 作成し、アップロード無視するファイルやディレクトリ等を設定。
7. レポジトリにプロジェクトのファイルやディレクトリを add する
$ git add .
8. commit する
$ git commit -m "コミットメッセージ"
9. push する
$ git push origin master

追記その1: --allow-unrelated-histories

上記フローで注意すべきなのは、add, commit, pushする前に pull すること。順番を間違えるとエラーが返ってくる。リモートから pull する前にローカルレポジトリにコミットしてしまった場合は、 --allow-unrelated-histories を追加すると良い:

$ git pull origin master --allow-unrelated-histories
$ git push --set-upstream origin master

追記その2: git clone してプロジェクトの中身をコピー

もしくは GitHub レポジトリ作成後、git cloneしてできたディレクトリにプロジェクトの中身を移動して add,commit,push するのも良いのかも。

1
2
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
2