Githubへのソースコードのあげ方

ローカルリポジトリの作成

ディレクトリを作成し、移動してからgit initリポジトリとして初期化させる。
initすることで.gitが新規作成される。.gitは隠しフォルダなので「command」+「shift」+「.」で表示させる。
gitでエラーが出た場合.gitを削除して再度git initすることがある。

$ mkdir ディレクトリ名
$ cd ディレクトリ名
$ git init

originにリモートリポジトリのURLを登録する。

origin=Github(リモートリポジトリ)の事
git remote add origin リポジトリURLを打ち、originという名前でgithubのブランチを追加。

$ git remote add origin https://github.com/~~~~~.git
$ git remote -v
origin  https://github.com/~~~~~~.git (fetch)
origin  https://github.com/~~~~~~.git (push)

リポジトリとは

バージョン管理によって管理されたファイルやディレクトリの状態や変更履歴を保管するところをリポジトリと呼ぶ。
リポジトリの種類:

ユーザーの紐付け

GitHubのユーザー名とメールアドレスを登録する

git config --global user.name ユーザ名

git config --global user.email メールアドレス

#以下のコマンドを入力し登録できてるか確認
owner@ownernoMacBook-Pro scaffold_app % git config --list
credential.helper=osxkeychain
user.name=ユーザー名
user.email=メールアドレス
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true

開発過程をリモートリポジトリへ登録する流れ


  • ステージング(add): ワークツリー(実際に作業してるディレクトリ)で変更があるファイルをステージングエリアへ追加する
  • コミット(commit): ステージングエリアからローカルリポジトリへ登録
  • プッシュ(push): ローカルリポジトリに登録されたファイルをリモートリポジトリへ追加
$ git add -A
$ git commit -m 'コミットメッセージ'
#GitHubは2020年10月から、新規作成リポジトリのデフォルトブランチを「main」という名前に変えたので切り替える
$ git branch -M main

コミットメッセージ書き方

  • fix:バグ修正
  • hotfix:クリティカルなバグ修正
  • add:新規(ファイル)機能追加
  • update:機能修正(バグではない)
  • change:仕様変更
  • clean:整理(リファクタリング等)
  • disable:無効化(コメントアウト等)
  • remove:削除(ファイル)
  • upgrade:バージョンアップ
  • revert:変更取り消し

リモートリポジトリの作成

トップページからnewを選択

  • Repository nameに任意のリポジトリ名を入力。
  • Initialize this repository with:はリポジトリを初期化する時の設定。
  • ローカルにあるソースコードを入れる場合、チェックは入れなくていい。

Create repositoryでリポジトリが作成される。

リモートリポジトリへpush!!

pushとはローカルリポジトリgithubのリモートリポジトリへ反映すること。以下を実行する。

#以下のコマンドでローカルリポジトリの変更をリモートリポジトリへ反映
$ git push -u origin main
Enumerating objects: 2756, done.
Counting objects: 100% (2756/2756), done.
Delta compression using up to 8 threads
Compressing objects: 100% (1885/1885), done.
Writing objects: 100% (2756/2756), 78.97 MiB | 10.77 MiB/s, done.
Total 2756 (delta 804), reused 0 (delta 0)
remote: Resolving deltas: 100% (804/804), done.
remote: warning: See http://git.io/iEPt8g for more information.
remote: warning: File volumes/db/data/ibdata1 is 76.00 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
To https://github.com/meo2718/crud_app_java.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.