2012-01-18 87 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

相关问题