LoginSignup
2
4

More than 5 years have passed since last update.

githubのサブアカウントでコミット&プッシュする

Last updated at Posted at 2017-08-11

複数gitアカウントを持つPCで作業すると自分のgitアカウントに仕事用アカウントでコミットしたりと誤爆する。
かといってPC毎にSSH設定するのがめんどいのでよくやる手段を備忘録として残しておく
(PC変わったり複数PCで同一アカウントでコミットしたい場合とか)
下のコマンド実行後にコミット&プッシュすれば
ローカルリポジトリはサブアカウントでコミット
プッシュもサブアカウントの方でプッシュ

git clone https://(アカウントユーザ名):(パスワード)@github.com/(アカウントユーザ名)/(リポジトリ名).git
cd (リポジトリ名)
git config --local user.name "(アカウントユーザ名)"
git config --local user.email "(アカウントemail)"

シェルスクリプト:

subclone.sh
#!/bin/sh
path=$1
username="サブアカウント名"
password="サブアカウントパスワード"
email="サブアカウントEmail"

git clone https://${username}:${password}@github.com/${username}/${path}.git
cd ${path}
git config --local user.name "${username}"
git config --local user.email "${email}"

使い方:

./clone.sh (リポジトリ名)
2
4
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
4