LoginSignup
2
3

More than 3 years have passed since last update.

ローカル環境でのGithub連携方法

Last updated at Posted at 2021-03-05

はじめに

ローカル環境でのGithub連携方法についてまとめました。
railsアプリをGithubに連携させるためには、gitの知識も必要なため、gitを含めて説明します。

到達点

以下の2点を達成する
・gitが使えるようになる
・railsアプリをGithubに連携させる

流れ

① railsアプリを作成
② Github新規登録し、リポジトリを作成
③ gitコマンドを行い、連携させる

① railsアプリを作成

手前味噌ではありますが、私の記事を参照すると、ローカル環境でのrails環境構築ができます。
ローカル環境開発 Ruby on Railsの環境構築方法

  

② Github新規登録し、リポジトリを作成

Githubを新規登録し、新しいリポジトリを作成する。

以下の画像の赤枠の New もしくは New repository をクリックしてください。

スクリーンショット 2021-03-01 19.29.40.png

Repository nameは、自身のアプリ名(rails new アプリ名)を入力し、Create Repositoryをクリックしてください。

スクリーンショット 2021-03-01 19.24.22.png

③ gitコマンドを行い、連携させる

$ cd 自分のアプリ名
$ git init
$ git status   #作業ディレクトリでの現在の状態を表示する
$ git diff     #差分を見る
$ git add ..   #すべてのファイル・ディレクトリ

git addでファイルをstagedという状態にします
git add する前に変更した箇所とインデックスとの変更点を必ず確認しましょう

  

$ git commit -m "Initialize repository"

git commitでローカルレポジトリにコミットします
git commit -m"コミット名" でコミット名が作成できます。

$ git remote add origin http://Github.com/GitHubで作成したID/リポジトリ名.git
$ git push -u origin master

git pushで、ローカルレポジトリの内容がリモートに反映されます。
Githubのページからも確認しましょう。

参考記事

今日からはじめるGitHub 〜 初心者がGitをインストールして、プルリクできるようになるまでを解説

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