Git@OSC & SSH配置


#### [ 导入外部Git仓库到中国源代码托管平台(Git@OSC)]

免费代码托管 您可以通过SSH或者HTTP的方式提交和管理代码,也可以通过Web的方式在线阅读,编辑代码与Team@OSC的集成 代码托管与团队协作的一体化服务式管理平台,轻松管理源代码。

 

------------------------------------------

## 方案1:

从原始地址clone一份bare仓库

$ git clone --bare  https://github.com/bartaz/impress.js.git (例子)

在Git@OSC上创建一个项目(http://git.oschina.net/projects/new),这里注意,不要勾选使用Readme初始化项目,不要选择项目的授权协议和.gitignore 文件,因为这些会导致项目有第一个提交。

记下新建项目后的地址,推荐使用http或者ssh方式皆可,大项目推荐ssh方式。

$ cd impress.js.git

$ git push --mirror git@git.oschina.net:username/impress-js.git

此命令执行完成后即完成导入,删除 impress.js.git 文件夹即可。

## 方案2:

此方案,手头已经有了项目的完成仓库,则无需再从第三方代码托管平台上clone下来。

到Git@OSC上创建项目,同样不要选择以上所说的三项。

命令行进入项目目录,git status 确保项目状态为:

  nothing to commit, working directory clean

如果状态不是这样,则需要通过提交、暂存等操作,使项目当前状态为clean。

添加Git@OSC的remote

$ git remote add git-osc git@git.oschina.net:username/translate4j.git

推送所有分支和tags

$ git push git-osc --all

$ git push git-osc --tags

以上两条命令执行完毕,即完成导入。

## 方案3:

此方案针对导入已有的SVN仓库

同上,先新建项目,不要选择以上所说的三项

使用git-svn工具clone svn仓库,git-svn 已经是Git的默认组建,如果你安装的是较新版本的Git客户端的话,则不需要再单独下载这个组件

$ git svn clone http://translate4j.googlecode.com/svn/trunk/ translate4j

同样,进入项目目录,添加remote

$ git remote add git-osc git@git.oschina.net:username/impress.js.git

同样,推送所有分支和标签

$ git push git-osc --all

$ git push git-osc --tags

以上两条命令执行完毕,即推送完成

------------------------------------------

配置SSH

SSH 为 Secure Shell 的缩写,安全外壳协议:SSH 为建立在应用层和传输层基础上的安全协议。

(公钥 & 私钥)利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。

--同样,在GitHub上实现过程一样。

1、创建SSH:

$ ssh-keygen -t rsa -C “xxxx@xxx.com"

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/Belief/.ssh/id_rsa): git_os_rsa 

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in git_os_rsa.

Your public key has been saved in git_os_rsa.pub. 

The key fingerprint is:

07:73:91:05:e4:1b:6b:d4:94:ed:4d:55:50:ae:4a:f8 1605319671@qq.com

The key's randomart image is: 

+--[ RSA 2048]----+

|         .++oo.o*|

|         ..+. ...| 

|        o = .. o.|

|         = =  ...| 

|        S * . .  |

|         o o .   |

|            E    |

|                 |

|                 |

+-----------------+

2、将公钥添加到剪贴板,再添加(粘贴)到网页中

$ pbcopy < ~/.ssh/id_rsa.pub

# Copies the contents of the id_rsa.pub file to your clipboard

3、本地验证:

$ eval "$(ssh-agent -s)" 

Agent pid 2815

$ ssh-add ~/.ssh/git_os_rsa

Enter passphrase for /Users/Belief/.ssh/git_os_rsa:

Identity added: /Users/xxx/.ssh/git_os_rsa (/Users/xxx/.ssh/git_os_rsa)

$ ssh -T git@git.oschina.net

Welcome to Git@OSC, SpongeBob_Han!

4、导入工程:

$ git clone https://github.com/bartaz/impress.js.git

[ 用 "$ git clone 仓库HTTPS地址",将其导出到"$ cd Desktop"桌面! ]

------------------------------------------

|-> GitHub: SpongeBob-GitHub

|--> Copyright (c) 2015 Bing Ma.



" There's always more to learn, and there are always better ways to do what you've done before. " -- Trybst


原文地址:https://www.cnblogs.com/Trybst/p/4494185.html