第三章

Git使用入门

1.1安装Git

#apt-get install git

#apt-get install git-doc git-svn git-email git-gui gitk

#yum install git

#yum install git-doc git-svn git-email git-gui gitk

1.2查看Git文档

#man git-checkout          //查看指定命令的帮助文档

#git help <sub-command>    //以文本形式查看指定文档

#git help git-checkout        //查询git-checkout命令的文档

#git help –w git –checkout    //查看HTML格式文档

1.3源代码的提交和获取(Git功能)

  1.3.1创建版本库:git  init

Git版本库分为本地版本库和远程版本库,访问本地版本库不需要任何权限

#mkdir –p /demo/helloworld-git    //建立一个开源工作项目的目录

#cd /demo/helloworld-git         //进入该目录

#git init                        //创建版本库

1.3.2将文件提交到本地版本库:git commit

#cd /demo/helloworld-git              //进入Git目录

#echo”helloworld”>helloworld.txt       //创建一个helloworld.txt文档

#git add helloword.txt                 //将helloworld.txt文档加到本地版本库的索引中

#git commit –m ‘helloworld-master’      //将文件提交到版本库

#git log//显示日志信息

  1.3.3创建本地分支:git branch

#git branch             //浏览版本库中的本地分支

#git branch new-branc    //建立一个新的分支

#git branch –D new-branch   //删除刚刚建立的分支

 1.3.4切换本地分支:get checkout

#git checkout new-branch//将当前本地分支切换到new-branch上

 1.3.5在GitHub上创建开源项目

Git管理源代码使用远程的Git托管服务器,使用GitHub来托管刚才创建的文件。

 1.3.6上传源代码到GitHub:git push

#ssh-keygen –t rsa –C helloworld@126.com

#ssh –T git@github.com

#ssh-add

#git config –global user.name”Your Name”

#git config –global user.email helloworld@126.com

#git remote add origin git@github.com:androidguy/helloworld.git

#git push –u origin master

#git branch –a

 1.3.7从GitHub下载源代码:git clone

#git clone  git@github.com:androidguy/helloworld.git

原文地址:https://www.cnblogs.com/yajuan2013/p/5445856.html