LoginSignup
2
1

More than 3 years have passed since last update.

gitで別のアカウントにpush/pullしたい場合

Last updated at Posted at 2021-03-01

普段使わないリポジトリへのアクセスが必要になった際、複数githubアカウントの管理が必要になりそうだったのでメモ。

仕事用と個人用など頻繁に切り替える必要がある方は下記の記事を参考することを推奨します。
複数のgitアカウントを使用する場合

今回は、「1つのリポジトリのみ適用したい」という方向けな気がします。

変更すべき場所の確認

コマンド
$ cd .git/config
$ cat config

[core]
・・・
[remote "origin"]
        url = https://github.com/[ユーザー名]/[リポジトリ名].git # 変更箇所
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
・・・

remoteのurlを変更

コマンド
$ git remote set-url origin https://[ユーザー名]:[パスワード]@github.com/[ユーザー名]/[リポジトリ名].git

localを設定

これを設定しておかないと、コミット履歴にglobalで設定してあるアカウントが適用される。
sh:
$ git config --local user.name "[ユーザー名]"
$ git config --local user.email "[メールアドレス]"

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