初期設定手順
- ホストファイル編集
GitLabサーバーIPアドレス gitlab.example.jp
- ユーザー情報設定(GitLabアカウントに合わせて変更)
git config --global user.name "kanako"
git config --global user.email "kanako@example.co.jp"
# LF形式でのコミット設定
git config --global core.autocrlf input
# 混合改行の検証強制
git config --global core.safecrlf true
# 大文字小文字区別設定
git config core.ignorecase false
- SSH鍵ペア生成
GitLabの[設定]→[SSHキー]から公開鍵を登録 生成コマンド:
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitlab
vi ~/.ssh/config
# 設定内容
Host gitlab.example.jp
HostName GitLabサーバーIP
IdentityFile ~/.ssh/id_rsa.gitlab
User developer
chmod 600 ~/.ssh/*
- リポジトリ取得(SSH形式推奨)
cd ~/projects/
# 最新バージョン
git clone git@gitlab.example.jp:team/project.git
# 旧バージョン
git clone git@gitlab.example.jp:legacy/project.git
# HTTP形式で取得した場合の修正
vi .git/config
開発フロー概要
=
- ローカル環境構築 ==================
# プロジェクト取得例
$ git clone git@gitlab.example.jp:team/legacy-project.git
- 新規ブランチ作成 =================
機能開発ごとに個別ブランチを作成
# 開発用ブランチ作成
$ git checkout -b feature-xyz
# 最新コード取得
$ git pull origin main
- 変更内容のコミット ====================
$ git add --all
$ git status
$ git commit -v
$ git commit -m "改善案実装"
・git add --allは全変更ファイルを追加(Git2.0以降は.でも可)
・git statusで変更状況確認
・git commit -vで差分表示付きコミット
・-mオプションでコミットメッセージ入力
- コミットメッセージの作成ルール ==========================
必須フォーマット:
50文字以内の現在形要約
* 72文字以内の補足説明
* 72文字以内の追加説明
- メインブランチへのマージ =======================
$ git checkout main
$ git merge feature-xyz
・git checkout mainでメインブランチに切り替え
・git mergeで開発ブランチを統合
- リモートリポジトリ更新 =====================
$ git push -u origin main
- プルリクエスト作成 ====================
コードレビューの依頼と統合申請
※エラー時の修正方法:
$ git reset --hard HEAD~1
簡易フローまとめ:
git clone git@gitlab.example.jp:team/project.git
cd project
git checkout main
git pull origin main
git add .
git commit -m "機能追加"
git push -u origin main