1 先下载 Git for Windows
然后一直点下一步安装.
2 安装之后, 选择 Git gui. 生成 SSH 链接 Git 公钥.
用命令也可以:
$ SSH-keygen -t rsa -C "[email protected]"
然后输入密码.
建议用第一种方式. 第二种网上说是可以, 但是我没成功过.
然后输入密码.
3 将公钥添加到开源中国上, 或者是 GitHub 中
在开源中国中新建一个公钥, 然后将. SSH 文件夹下的 id_ras_pub 中的内容复制到文本框中, 这里的 title 可以随意.
4 测试链接:
输入命令:$ SSH -T [email protected]
然后输入 yes
如果成功可以看到你的用户名和邮箱.
出现错误可以测试:$ SSH -Tv [email protected]
5 设置用户名和邮箱
- $ Git config user.name"you name"
- $Git config user.email"[email protected]"
6 然后在 web 开源中国中创建一个 project.
7 测试上传文件
创建文件夹, 需要和你建立的 projexct 同名.
- mkdir hello
- cd hello
- Git init
- touch README
- Git add README
- Git commit -m 'frist commit'
8 提交
Git remote add test [email protected]:Web 用户名 / hell.Git
Git push -u test master
如里有报错误:
- To [email protected]:yangzhi/hello.Git
- ! [rejected] master -> master (fetch first)
- error: failed to push some refs to '[email protected]:yangzhi/hello.git'
- hint: Updates were rejected because the remote contains work that you do
- hint: not have locally. This is usually caused by another repository pushin
- hint: to the same ref. You may want to first merge the remote changes (e.g.
- hint: 'git pull') before pushing again.
- hint: See the 'Note about fast-forwards' in 'git push --help' for details.
可以输入:
Git push -f
可以 ok 了.
10 克隆代码
Git clone [email protected]: 用户名 / 项目名. Git
来源: http://www.bubuko.com/infodetail-3062683.html