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にアップロードする方法

Posted at

既存ファイルをGitHubに追加する

Gitで既存のファイルをアップロードする方法について手順をご紹介したいと思います。

1. GitBashを立ち上げ、GitHubにアップしたいファイルにcdコマンドで移動する
※ちなみに、cdはcreate directoryの略

2. git add . コマンドを打つ
cdコマンドで希望ディレクトリまで移動できたら、ステージに内容を追加するために、以下のコマンドを打ってください。

GitBush
$ git add .

3. git commit コマンドを打つ
git add . コマンドでステージに追加できたら、git commit でリポジトリに内容を追加します。

GitBush
$ git commit

4. remote repository を作成する
GitHubを開き、New Repositoryを開きます。
その後、repository nameに任意の名前を入れて、Create repositoryでrepositoryを作成します。

493edf904c9094ef7c0c39c2e6a566b6.gif

以上の作業が完了したら、次に、以下のコマンドを打ちます。

GitBush
$ git remote add origin https://github.com/Gitのアカウント名/作成したリポジトリ名.git
$ git push -u origin master

以上で、ファイルをGitHub上にアップできたと思います。

Git操作に不安がある方は、私も受講したUdemyの講座を受講するとよいかと思います!

考えられるエラーについて

リモートリポジトリを作成した直後に、上記コマンドを実行せずに、以下のコマンドを実行すると、以下のエラーが発生するので、ご注意ください。

失敗例
error: src refspec master does not match any.
解決方法
$ git add .
$ git commit 

加えて、もしかすると、git add . コマンドを打った時に、

エラー
warning: CRLF will be replaced by LF in .vscode/settings.json.
The file will have its original line endings in your working directory

このようなエラーが出るかもしれません。
この時は、以下のコマンドを試してみましょう。

解決方法
$ git config --global core.autoCRLF false

ちなみに、「https://qiita.com/yukari-n/items/e6107fe52772ef6a2df4」
を参考にさせていただきました。
※作成者様、ありがとうございます。

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?