Linux下使用git命令及github项目

来源:互联网 发布:内部类 java 编辑:程序博客网 时间:2024/06/06 13:16
在linux下搭建git环境
1、创建Github账号,https://github.com
2、Linux创建SSH密钥:
ssh-keygen  ##一直默认就可以了
3、将公钥加入到Github账户信息Account Settings->SSH Key
4、测试验证是否成功。
ssh -T git@github.comHi someone! You've successfully authenticated, but GitHub does not provide shell access.

同步github到本地
1、复制项目到本地:
git clone git://github.com:xxxx/test.git ##以gitreadonly方式克隆到本地,只可以读git clone git@github.com:xxx/test.git  ##以SSH方式克隆到本地,可以读写git clone https://github.com/xxx/test.git ##以https方式克隆到本地,可以读写git fetch git@github.com:xxx/xxx.git  ##获取到本地但不合并git pull git@github.com:xxx/xxx.git ##获取并合并内容到本地

本地提交项目到github
1、本地配置
git config --global user.name 'onovps'git config --global user.email 'onovps@onovps.com' #全局联系方式,可选
2、新建Git项目并提交到Github。
mkdir testdir & cd testdirtouch README.mdgit init #初始化一个本地库git add README.md #添加文件到本地仓库git rm README.md #本地倒库内删除git commit -m "first commit" #提交到本地库并备注,此时变更仍在本地。git commit -a  ##自动更新变化的文件,a可以理解为autogit remote add xxx git@github.com:xxx/xxx.git  #增加一个远程服务器的别名。git remote rm xxx   ##删除远程版本库的别名git push -u remotename master #将本地文件提交到Github的remoname版本库中。此时才更新了本地变更到github服务上。

分支版本操作
1、创建和合并分支
git branch #显示当前分支是mastergit branch new-feature  #创建分支git checkout new-feature  #切换到新分支vi page_cache.inc.phpgit add page_cache.inc.phpgit commit -a -m "added initial version of page cache"git push origin new-feature  ##把分支提交到远程服务器,只是把分支结构和内容提交到远程,并没有发生和主干的合并行为。
2、如果new-feature分支成熟了,觉得有必要合并进master
git checkout master  #切换到新主干git merge new-feature  ##把分支合并到主干git branch #显示当前分支是mastergit push  #此时主干中也合并了new-feature的代码

git命令使用思维图:【非常有料

http://www.cnblogs.com/1-2-3/archive/2010/07/18/git-commands.html