GitHub 是一个面向开源及私有软件项目的托管平台,因为只支持 Git 作为唯一的版本库格式进行托管,故名 GitHub。
网址:https://github.com/ sigh up for github注册账号.
注册账号并登陆后,会有一个帮助文档,告诉我们如何使用github。帮助文档包括: 建立仓库; 创建分支; 修改分支; 合入主线并关闭分支。
上传代码需要git2.0以上版本,因此我们不使用centos 6.2自带的git版本(大概为1.7)。首先安装git依赖:
yum -y install zlib-devel openssl-devel perl cpio expat-devel gettext-devel; yum install autoconf; yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel; yum install gcc perl-ExtUtils-MakeMaker; cd /usr/src/; wget https://www.kernel.org/pub/software/scm/git/git-2.1.2.tar.gz --no-check-certificate; tar xvf git-2.1.2.tar.gz; cd git-2.1.2; make prefix=/usr/local/git all; make prefix=/usr/local/git install; cho "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrc; source /etc/bashrc; git version;git version命令显示版本应该为2.1.2.至此,客户端工具已经安装成功。
1 设置git仓库身份认证:
git config --global user.email "xiongwei0218@gmail.com" git config --global user.name "David"2 在centos上产生密钥:
ssh-keygen -t rsa -C "youremail@example.com";获取秘钥(这里的邮箱跟刚才git官网上注册的一致)进入/root/.ssh目录下,找到一个rsa.pub(可能为id_isa.pub)的文件,将内容全部复制。
3 重新进入git网站,按照如下图操作将你刚才复制过来的内容填入文本框内即可生成SSH秘钥,这个秘钥用于保证托管代码的可靠安全:
4 下载项目并修改 下载:
git clone https://github.com/ShipeiXu/hello-world.git修改:
cd hello-world; touch test.c; git add test.c; git commit -m "添加test.c文件"; [root@localhost hello-world]# git commit -m "添加test文件" [master 09f69ac] 添加test文件 Committer: xushipei2009@163.com <root@localhost.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly: git config --global user.name "Your Name" git config --global user.email you@example.com After doing this, you may fix the identity used for this commit with: git commit --amend --reset-author 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test.c将内容托管至github:
git remote add two https://github.com/ShipeiXu/hello-world.git; git push -u two master; [root@localhost hello-world]# git push -u two master Username for 'https://github.com': **xushipei2009@163.com** Password for 'https://xushipei2009@163.com@github.com': Counting objects: 2, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 306 bytes | 0 bytes/s, done. Total 2 (delta 0), reused 0 (delta 0) To https://github.com/ShipeiXu/hello-world.git 23b22c6..09f69ac master -> master Branch master set up to track remote branch master from two.以上git push操作可能会出现如下提示: unable to read askpass response from ‘/usr/libexec/openssh/gnome-ssh-askpass; 如果有这个提示,执行unset SSH_ASKPASS操作就行了。
git –help命令 链接:http://www.cnblogs.com/cspku/articles/Git_cmds.html