git

githubリポジトリ作成と登録

githubにアカウントを作成されている事が前提です。今回は例題として、作成するリポジトリ名を「code-transformer-api」とし、説明文として「マルチフォーマット対応のエンコード・デコード Web API」を使います。

まずはGitHub にログインして…

  1. New repository をクリック
  2. Repository name に code-transformer-api と入力
  3. Description に マルチフォーマット対応のエンコード・デコード Web API
  4. Public / Private を選択
  5. README, .gitignore, License は作らない(後でローカルから push するため)
入力例

次に Create repository をクリック

すると、GitHub が push 用のコマンドを表示してくれる。これにならって、以下作業すすめる。

ローカルの Maven プロジェクトを Git 管理にする

プロジェクトのルートディレクトリで以下を実行

git init
git add .
git commit -m "Initial commit"

GitHub リポジトリと接続する

git remote add origin https://github.com/<your-account>/code-transformer-api.git
ここまでの実行例
sooni@mahirospc MINGW64 /c/work/code-transformer-api
$ pwd
/c/work/code-transformer-api

sooni@mahirospc MINGW64 /c/work/code-transformer-api
$ git init
Initialized empty Git repository in C:/work/code-transformer-api/.git/

sooni@mahirospc MINGW64 /c/work/code-transformer-api (main)
$ git add .
warning: in the working copy of '.gitattributes', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '.gitignore', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '.mvn/wrapper/maven-wrapper.properties', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'mvnw.cmd', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'pom.xml', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'src/main/java/com/oha_yo/codec/Application.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'src/main/java/com/oha_yo/codec/unicode/UnicodeController.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'src/main/java/com/oha_yo/codec/unicode/UnicodeService.java', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'src/main/resources/application.properties', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'src/test/java/com/oha_yo/codec/ApplicationTests.java', LF will be replaced by CRLF the next time Git touches it

sooni@mahirospc MINGW64 /c/work/code-transformer-api (main)
$ git commit -m "Initial commit"
[main (root-commit) 1d07fb2] Initial commit
 13 files changed, 676 insertions(+)
 create mode 100644 .gitattributes
 create mode 100644 .gitignore
 create mode 100644 .mvn/wrapper/maven-wrapper.properties
 create mode 100644 logs/api-server.loZg
 create mode 100644 logs/api-server.log
 create mode 100644 mvnw
 create mode 100644 mvnw.cmd
 create mode 100644 pom.xml
 create mode 100644 src/main/java/com/oha_yo/codec/Application.java
 create mode 100644 src/main/java/com/oha_yo/codec/unicode/UnicodeController.java
 create mode 100644 src/main/java/com/oha_yo/codec/unicode/UnicodeService.java
 create mode 100644 src/main/resources/application.properties
 create mode 100644 src/test/java/com/oha_yo/codec/ApplicationTests.java

sooni@mahirospc MINGW64 /c/work/code-transformer-api (main)
$

git add でwarning が出ているのは、プロジェクト内のファイルが LF で保存されているのに、 Git の設定が チェックアウト時に CRLF に変換するようになっているため、 「次に Git が触ったら CRLF に変えるよ」と警告しているだけ。このままでも問題ないけど、.gitattributesファイルを書き換えることで対策することできます。

ローカルのブランチ名を mainに変える

git branch -M main

ローカルと GitHub を接続する

git remote add origin https://github.com/oha-yo/code-transformer-api.git

main ブランチを GitHub に push

これで GitHub にアップロードされる。

git push -u origin main
ここまでの実行例
$ git branch -M main

atsuc@mahirospc MINGW64 /c/work/code-transformer-api (main)
$ git remote add origin https://github.com/oha-yo/code-transformer-api.git

atsuc@mahirospc MINGW64 /c/work/code-transformer-api (main)
$ git push -u origin main
Enumerating objects: 31, done.
Counting objects: 100% (31/31), done.
Delta compression using up to 16 threads
Compressing objects: 100% (21/21), done.
Writing objects: 100% (31/31), 10.91 KiB | 1.36 MiB/s, done.
Total 31 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/oha-yo/code-transformer-api.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

atsuc@mahirospc MINGW64 /c/work/code-transformer-api (main)
$
登録の確認

以下の通り登録できた事確認できます。できたと思ったら、意図せず「logs」フォルダも登録されていました。本来.gitignoreファイルを使って登録対象から外すものですね。一度gitに登録したものを今後GITの管理から外す方法はこちら

改行コードの扱いを明確にしておきましょう
スポンサーリンク
タイトルとURLをコピーしました