2012-01-18 37 views
2

我有一個現有的帳戶與Github和源被推到舊帳戶,但我需要切換到另一個新的(一些私人問題和公共問題)。如何將我的git存儲庫切換到另一個新帳戶?

$ git config --global user.name mynewprivate 
$ git config --global user.email [email protected] 
$ git remote add origin [email protected]:mynewprivate/mynewprivaterepo.git 
fatal: remote origin already exists. 

如何解決?

追問:

管理|從公共回購切換到|他自己的私人回購|推自己

1) I created the key files, private and public. 

$ ssh-keygen -t rsa -C "[email protected]" 
Generating public/private rsa key pair. 
Enter file in which to save the key (/home/sun/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/sun/.ssh/id_rsa. 
Your public key has been saved in /home/sun/.ssh/id_rsa.pub. 
The key fingerprint is: 
c3:1a:88:49:0e:0b:d0:2 [email protected] 
The key's randomart image is: 
+--[ RSA 2048]----+ 
|o+o    | 
|E..+    | 
|=++ .   | 
|+Xoo . .   | 
|=.* . . S  | 
| o  o .  | 
|  .   | 
|     | 
|     | 
+-----------------+ 

2) I copied it for backup if i lose it i can use it 

$ cp -R /home/sun/.ssh/id_rsa to /var/tmp/myprojectname.backup.key 

3) I went to github and created the public key from there site (SSH Public key) 

4) Then i tested if my system can communicate with git 

$ ssh -T [email protected] 
Hi {hubname}! You've successfully authenticated, but GitHub does not provide shell access. 

    It works! 

5) Project upload 

$ cd /var/www/html/myprject 
$ git remote rm origin 
$ git remote add origin [email protected]:myproject/myproject.git 

6) I followed as usual my IDE, now to load myproject.git and the private 
key that i saved in my /var/tmp/myprojectname.backup.key 
7) It started pushing, means uploading success... 

第三方開發商|可以訪問推送| Admin private repo

1) Admin adds your username in to there private repo 
2) In your personal username you get notice that you are allowed 
3) You accept and find the repository details in your own account 
4) You do following: 

$ ssh-keygen -t rsa -C "[email protected]" 
    save the file to /var/tmp/yourproject.name.key 
$ cd /var/www/html/localproject 
$ git init 
$ git remote add origin [email protected]:private/private.git 

5) Now you can push to the private repo 

回答

6

看起來你已經有了一個遠程命名的起源。刪除它,然後重新創建它。

git remote rm origin 
git remote add origin [email protected]:mynewprivate/mynewprivaterepo.git 

如果你想知道爲什麼它的失敗,雖然,檢查出的.git/config中,你會看到老遠程在那裏。與上述兩個命令相同的另一種方法是編輯該文件。

+0

謝謝你的作品。 – YumYumYum 2012-01-18 19:14:52

+0

如果你只是改變網址,你可以執行'set-url' – manojlds 2012-01-18 19:44:54

相關問題