LoginSignup
10
13

More than 5 years have passed since last update.

サルでもできるCodeCommit コピペでgit cloneするまで

Last updated at Posted at 2015-07-14

CodeCommitにリポジトリを作成

  1. バージニアリージョンでCodeCommitにアクセス→Get Started->リポジトリ名:sample_ripoを入力

リポジトリにアクセス出来るIAMユーザを作る

  1. IAMユーザ:codecommitを作成してアクセスキーID:XXXとシークレットアクセスキー:YYYをメモる。
  2. ポリシーのアタッチ→検索窓にcodecommitと入力→ポリシータイプ:AWSCodeCommitFullAccessを選択

ec2インスタンスにログインして、リポジトリにアクセスする

  1. ec2にec2-userでログインした後に初期設定をするスクリプト init_codecommit.shを作成して実行します。
init_codecommit.sh
#!/bin/bash

# aws cliを最新にアップデート
sudo pip install --upgrade awscli

# aws cliのconfig設定をします
mkdir ~/.aws
cat <<\_EOT_ > ~/.aws/config
[default]
region = us-east-1
_EOT_

# XXX,YYYはIAMユーザのID
cat <<\_EOT_ > ~/.aws/credentials
[default]
aws_access_key_id = XXXXXXXXXXXXXXXXXXXXXXX
aws_secret_access_key = YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
_EOT_

# gitのconfigを設定。name,email,aliasは各自の設定してください
# 以下のコマンドで設定するのと同じ事を記述
# git config --global user.name "ec2-user"
# git config --global user.email ec2-user@example.com
# git config --global credential.helper '!aws codecommit credential-helper $@'
# git config --global credential.UseHttpPath true

cat <<\_EOT_ > ~/.gitconfig
[user]
  name = ec2-user
  email = ec2-user@example.com
[credential]
  helper = !aws codecommit credential-helper $@
  UseHttpPath = true
[alias]
  co = checkout
  cm = commit
  ce = commit -v --amend
  st = status
  ss = status --branch --short
  si = status --ignored --short
  br = branch
  branches = branch -a
  remotes = remote -v
  tags = tag -l
  lg = log --graph --all --decorate --abbrev-commit --branches --date=short --pretty=format:\"%C(red)%h%C(reset) %C(green)[%ad]%C(res
et) %s %C(cyan)@%an%C(reset) %C(yellow)%d%C(reset)\"
  fp = fetch --prune
  dh = diff --histogram
  dw = diff --word-diff
  dc = diff --cached
  wc = whatchanged
[push]
  default = current
_EOT_

# testリポジトリをcloneしてみる
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/sample_ripo ~/samlpe_ripo
  • git リポジトリが使えるか軽く確認
リポジトリのディレクトリ確認
$ ls

移動
$ cd test_ripo

ステータス
$ git status

hogeファイルを作成
$ echo hoge > hoge

ステータス確認
$ git status

hogeファイルを追加
$ git add hoge

hogeファイルをコミット
$ git commit -m 'add hoge'

ログ表示
$ git log

りモートリポジトリへプッシュ
$ git push origin master

無事にgitが動いていれば成功だね!

関連するページ

サルでもできるCodeCommit ssh接続でgit cloneするまで

10
13
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
10
13