[ git ] git托管代码

来源:互联网 发布:皂基洗面奶知乎 编辑:程序博客网 时间:2024/05/16 13:54

久闻git大名,但是一直不知道为何物。现在认真的过了一遍。原来是和svn一样的版本控制器。

具有速度快,分布式管理等优点。

现在就来看看git的使用过程,我这里是用开源中国来托管代码的,如果是使用github也是一样的。

1 先下载git for windows

然后一直点下一步安装.

2 安装之后,选择git gui.生成ssh 链接 git 公钥.

用命令也可以:

$ ssh-keygen -t rsa -C "your_emali@youemal.com"

然后输入密码.

建议用第一种方式。第二种网上说是可以,但是我没成功过。

然后输入密码。

3 将公钥添加到开源中国上,或者是github中

在开源中国中新建一个公钥,然后将.ssh文件夹下的id_ras_pub中的内容复制到文本框中,这里的title可以随意.

https://help.github.com/articles/generating-ssh-keys


4 测试链接:

输入命令:$ ssh -T git@git.oschina.net

然后输入yes

如果成功可以看到你的用户名和邮箱.

出现错误可以测试:$ ssh -Tv git@git.oschina.net


5 设置用户名和邮箱

$ git  config user.name"you name"

$git  config user.email"you_email@youemal.com"


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 git@git.oschina.net:web用户名/hell.git


git push -u test master

如里有报错误:

[plain] view plaincopy
  1. To git@git.oschina.net:yangzhi/hello.git  
  2.  ! [rejected]        master -> master (fetch first)  
  3. error: failed to push some refs to 'git@git.oschina.net:yangzhi/hello.git'  
  4. hint: Updates were rejected because the remote contains work that you do  
  5. hint: not have locally. This is usually caused by another repository pushin  
  6. hint: to the same ref. You may want to first merge the remote changes (e.g.  
  7. hint: 'git pull') before pushing again.  
  8. hint: See the 'Note about fast-forwards' in 'git push --help' for details.  


可以输入:

git push -f 

可以ok了.

10 克隆代码

git clone git@github..com:用户名/项目名.git



转自:http://blog.csdn.net/yangzhihello/article/details/9855997



0 0
原创粉丝点击