LoginSignup
1
1

More than 1 year has passed since last update.

複数アカウントのAWS CodeCommitを管理する時のgit clone時tips

Posted at

自分で3回調べ直したので手順メモ。

背景

  • AWS CodeCommitにあるリポジトリをcloneしたい
    • 利用するAWSアカウントが複数あるため、 git config --global したくない
    • (もっとスマートな方法もありそうだが)都合よく切り替えるため初回git clone時に追加の操作を足す。

参考

大枠はこちらの方法です。

todo

1. AWS Credencial設定

aws configure --profile wasshoi

「wasshoi」部分は案件に応じてお好みで。

2. gitに対してまずは素直にglobal設定

git config --global credential.helper "!aws codecommit --profile wasshoi credential-helper $@"
git config --global credential.UseHttpPath true

3. リポジトリを使いたいディレクトリ配下で特定Credencialを読ませる

direnvを利用。

設定。
mkdir ~/projects/wasshoi/
cd ~/projects/wasshoi/
vim .envrc
.envrc
export AWS_PROFILE=wasshoi
export AWS_DEFAULT_REGION=ap-northeast-1
反映。
direnv allow

4. ひとまず素直にgit clone

git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/sample-repo
cd sample-repo

git clone用のurlはAWSコンソールから拾ってこれる。今回とってくるリポジトリは「sample-repo」という名前としておく。

5. 個別にgit設定

git config credential.helper "!aws codecommit --profile wasshoi credential-helper $@"
git config credential.UseHttpPath true

該当リポジトリ配下の .git/config に追記される。

6. gitのglobal設定を削除

vim ~/.gitconfig

↓
# ファイル内の以下箇所を削除してしまう
[credential]
    helper = !aws --region ap-northeast-1 --profile wasshoi codecommit credential-helper $@
    UseHttpPath = true

7.完了。

その他、mac端末の事情として以下対応するケースもあるがそれはまた別の話。


direnv設定など冗長に見える部分もあるが、まあ自環境での事情を加味したやや個人的な手順としてご容赦。

1
1
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
1