1
2

More than 1 year has passed since last update.

Githubにpushする方法

Last updated at Posted at 2021-06-21

やりたいこと

ローカルのファイルをGithub上にpushする。

Githubとは

エンジニアが各々のプログラムをアップして自分以外のエンジニアと共有する場所
vJ9K9dP.png

サンプルファイル

今回は例として下記のtest.htmlを使用し、Githubに上げてみます。

<html>
<head>
<title>Hello world !</title>
</head>
<body>
<h1>Hello world !</h1>
</body>
</html>
  1. 対象フォルダに移動
cd test

2.Gitリポジトリ作成 - 対象フォルダをGit管理対象に設定

git init

3.現在の状態を確認

git status

すると、まだインデックスに登録されていないため、下記のようなエラーが出る。
インデックスとは、ローカルリポジトリとリモートリポジトリの間の場所。
Gitではコミットした時に、リモートリポジトリにダイレクトにコミットするのではなく、その間にあるインデックスにあるものをコミットするようにしている。

On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        test.html

nothing added to commit but untracked files present (use "git add" to track)

4.インデックスに追加する

git add test.html

5.コミット - インデックスにあるファイルをコミット

git commit -m "add new file"

6.リモートリポジトリに接続

git remote add origin (自身のリモートリポジトリのURL)

7.リモートリポジトリにpush

git push origin master

追記
ブランチ作成

git branch -M ブランチ名

作成したブランチにpush

git push -u origin ブランチ名
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