LoginSignup
17
11

More than 3 years have passed since last update.

SourceTreeでリポジトリ毎にユーザーを切り替える

Last updated at Posted at 2019-03-27

概要

仕事用と個人開発用でアカウントを使い分けたい時があります。
リポジトリ毎にユーザーを設定できるように変更します。

HTTPSでクローンする前提

環境

Mac
SourceTree 3.1.1
※メインアカウント(グローバルユーザー)とは別のアカウントを使う場合を想定しています。

クローン

はじめにHTTPSでクローンします。
img_1_1.png

URLにアカウントとパスワードを記載します。
https://github.com/ryu0922/ysg_snowshoe.git

https://[ユーザー名]:[パスワード]@github.com/ryu0922/ysg_snowshoe.git
img_1_2.png

今のままだとSourceTreeに設定しているグローバルユーザーでpushします。
※添付だとわかりづらいですが、ryu*****0922が私のグローバルユーザーになります。
img_2_1.png

SourceTree設定

1.画面右上の設定を選択。
2.グローバルユーザー設定を使うのチェックを外す。
3.使用するアカウントの名前パスワードを設定。
img_2_2.png

4.リモートを選択。
5.Configファイルを編集を選択。
img_2_3.png

6.pushurl = https://[ユーザー名]:[パスワード]@github.com/ryu0922/ysg_manx_sp.gitを追記。
7.nameemailを使用するアカウントの設定に書き換え。
8.保存し、OKを選択。

完成形
※リポジトリの設定によってconfigの内容が違います。

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://ryu0922@github.com/ryu0922/ysg_snowshoe.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    pushurl = https://ryu0922:***@github.com/ryu0922/ysg_snowshoe.git
[branch "master"]
    remote = origin
    merge = refs/heads/master
[user]
    name = ***
    email = ***@***.com

pushするとユーザーの切り替えができています
img_2_4.png

間違えていたり、気になる点がありましたら教えていただけると嬉しいです。

17
11
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
17
11