LoginSignup
0
0

More than 3 years have passed since last update.

bitbucketのprivateリポジトリからgo modする

Last updated at Posted at 2020-12-22

背景

  • bitbucketで管理しているprivateなリポジトリから他のgo言語のモジュールを使いたい
  • ソースコードは公開したくない

前提

  • bitbucketにアクセスできるSSH鍵を登録している
    • 補足:Personal settings > SSH 鍵
  • この記事はgo version go1.14.2 darwin/amd64 で書いています
    • これ以前のバージョンであると他の設定が必要かもしれません

ローカル設定

SSH鍵を登録していればgitコマンドを使用してcloneやpushなどSSHプロトコルで行うことができるがgo get はhttpsプロトコルを使ってアクセスしている。

なのでgit(bitbuket)からSSHプロトコルを使って取得するために以下の設定を行う

git config --global url."git@bitbucket.org:".insteadOf "https://bitbucket.org/"

以下が追加されていること

$ cat ~/.gitconfig 
[url "git@bitbucket.org:"]
    insteadOf = https://bitbucket.org/

go側も以下の設定をしておく

export GOPROXY=direct
export GOSUMDB=off

Tips

    server response: Access denied. You must have write or admin access.

このエラーが出たら上記の設定が足りていない可能性がある

Go Get

モジュールを取得

go get -v bitbucket.org/[WORKSPACES]/[repository]

おまけ

別ブランチから取得したいなら

go get -v bitbucket.org/[WORKSPACES]/[repository]@[branch]
0
0
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
0
0