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?

More than 3 years have passed since last update.

[GitHub] 基本の使い方

Last updated at Posted at 2021-01-29

環境

macOS

Gitのインストール、
GitHubのアカウントの作成
が済んでいることが前提です。

リモートリポジトリを作成する

GitHubにログインし、右上の + ボタンから Create Repository をクリックします。

Repository name にリポジトリ名を決めて入力します。
次にリポジトリの種類を PublicPrivate を選択します。
( リポジトリの説明や使い方を記述するREADMEファイルを事前作成しておく場合は Initialize this repository with:Add a README file にチェックを入れます。)
そして、一番下の Create repository をクリックしてリポジトリを作成します。

ローカルリポジトリを作成する

今回は tweet_app というディレクトリにローカルリポジトリを作成します。(まだGitHubにアップするファイルがない場合はディレクトリを作成し、 cd で作成したディレクトリに移動します。)
tweet_app には既に index.html などのファイルが保存されています。
tweet_app ディレクトリに移動して git init コマンドを入力します。

$ cd tweet_app

$ git init

gitのインデックスに追加する

git add 移動したいファイル名 のコマンドでファイルの作成、変更、削除をインデックスに追加します。
インデックスとは、リポジトリにコミットする準備をするために変更内容を一時的に保存する場所のことです。
(cd で作成したディレクトリに移動してから実行します。)

$ git add index.html

ローカルリポジトリにコミットする

git commit -m "コミットメッセージ" で先ほどインデックスに追加したファイルをコミットします。
コミット(commit) とは、ファイル追加や変更の履歴をリポジトリに記録することです。
コミットメッセージ には簡潔に変更内容などを書きます。

$ git commit -m "add new file"

ファイルが追加されているか確認するコマンドです。
gitの管理下にあるファイルが表示されます。

$ git status

次に、リモートリポジトリの情報を git remote add origin リモートリポジトリのアドレス で追加します。この情報は、GitHub上に表示されるリモートリポジトリのアドレスです。(アドレスは緑のCodeボタンを押すと表示されます)

$ git remote add origin https://github.com/,,,/,,,.git

ローカルリポジトリをプッシュしてリモートリポジトリへ反映させる

git push origin master でプッシュします。

$ git push origin master

GitHubのユーザ名とパスワードを入力すると、プッシュしてリモートリポジトリへ反映させることに成功します。

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?