LoginSignup
0
2

More than 1 year has passed since last update.

ローカルで開発したプロジェクトをGithubに上げる手順

Last updated at Posted at 2022-02-05

まずはgitインストールをしてください。

【プロジェクトはじめ】

(1)githubにプロジェクトを作成する

githubでNewでリポジトリを作成。kegoなど、任意のプロジェクト名を作成します。

  1. New押す
    image.png
  2. project名(ここではkego)を入力、publicのままでcreate repositoryを押す
    image.png
  3. kegoプロジェクトが作られる
    image.png

(2)ローカルにプロジェクトを作成してgithubにあげる

ローカルにプロジェクトを作成します。
なお、mac操作なのでwindowsの場合はpowershellを使うといいと思います。

  1. プロジェクトを作成する$ mkdir kego ※ローカルプロジェクトとgithubに作ったプロジェクト名は別でも良いが一緒のほうがわかりやすい

image.png

  1. ローカルプロジェクトに移動$ cd kego/
    image.png

  2. gitリポジトリを作成$ git init
    ※ここでgitが登場します。gitインストールしてないと使えないので注意。
    image.png
    git 管理することがはじまる

  3. 適当にファイルを作成する$ touch index.html $ vim index.html

  4. 以下のコードをコピーして保存する:wq

<!DOCTYPE html>
<html>
<head>
  <title>gitテスト</title>
  <meta charset="UTF-8">
</head>
<body>
  <h1>gitテスト</h1>
</body>
</html>

image.png

  1. gitリポジトリにファイルを追加する$ git add .
    image.png

  2. gitファイルをコミットする$ git commit -m "first Commit"
    image.png

  3. 1で作成したリポジトリのURLをコピーしてリモートリポジトリに設定する$ git remote add origin git@github.com:yutoonodera/kego.git
    今の状態だとローカルでgit管理はできているが、ローカルのkegoフォルダとgithub上のkegoプロジェクトは何も関係していないのでローカルのkegoフォルダとgithub上のkegoプロジェクトを紐付ける
    image.png

  4. ファイルをプッシュする $ git push -u origin master
    image.png

  5. githubにソースがあげれた(=ローカルとgithubリポジトリが連携した)
    image.png

※実際の状況に合わせてソースを改修してみる

実際は新たにプロジェクトを作成するよりもすでにあるプロジェクトをローカルにもってきて改修してgithubにあげる場合のほうが圧倒的に多いはずなのでその流れを書きます。

  1. githubからソースをローカルに$ git clone git@github.com:yutoonodera/kego.git
    image.png

image.png

  1. masterからfix/h1-textブランチを作成し、fix/h1-textに移動する$ git checkout -b fix/h1-text
    image.png

  2. fix/h1-textブランチでソースを修正する
    image.png

  3. gitリポジトリにファイルを追加する$ git add .
    image.png

  4. gitファイルをコミットする$ git commit -m "h1-text fix Commit"
    image.png

  5. ファイルをプッシュする $ git push -u origin fix/h1-text
    image.png

  6. githubに反映されていることを確認
    image.png

  7. これでgit/githubを使った基礎的な改修は終わりです。このあとはgithub上でfix/h1-textブランチからmaster向けのプルリクエストを作ったりしてステージング環境や本番環境にマージしていく流れになるかと思います。

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