什么是Git
Git是分布式版本控制系统。
一、本地仓库的使用
下载安装
-
Linux:apt-get install git
二、远程仓库的使用
1) 注册github用户
2) 新建+ (New repository)版本库
3) 本地创建ssh公钥和私钥(Git Branch子弹)
ssh-keygen -t rsa -C "xiangfeijava@163.com"
4)将公钥设置到github上,Settings-> SSH and GPG keys -> New SSH Key, 将id_rsa.pub的内容复制到Key对应的输入框中,点击Add SSH Key即可。
5) 本地版本库和远程版本库关联
i) 克隆远程版本库到本地
git clone http://github.com/xiangffgh/helloworld.git
ii)将已有的本地库关联到远程
git remote add origin https://github.com/xiangffgh/helloworld.git
6)远程更新和提交
git push origin master //提交
git pull origin master //更新到最新版本
7)分支管理
1、创建本地分支 local_branch
git branch local_branch
2、创建本地分支local_branch 并切换到local_branch分支
git checkout -b local_branch
3、切换到分支local_branch
git checkout local_branch
4、推送本地分支local_branch到远程分支 remote_branch并建立关联关系
a.远程已有remote_branch分支并且已经关联本地分支local_branch且本地已经切换到local_branch
git push
b.远程已有remote_branch分支但未关联本地分支local_branch且本地已经切换到local_branch
git pull origin dev 本地分支与远程分支相关联
c.远程没有有remote_branch分支并,本地已经切换到local_branch
git push origin local_branch:remote_branch
d.在本地新建分支并推送到远程
git checkout -b test
git push origin test 这样远程仓库中也就创建了一个test分支
e.创建分支并直接关联远程分支
git checkout -b 本地分支名称 origin/远程分支名称
5、删除本地分支local_branch
git branch -d local_branch
6、删除远程分支remote_branch
git push origin :remote_branch
git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。
git branch -d | -D branchname 删除branchname分支
git branch -d -r branchname 删除远程branchname分支
7、查看本地分支
git branch
8、查看远程和本地分支
git branch -a
三、常用命令和技巧
相关优秀书籍
https://git-scm.com/book/zh/v2 (官方提供)
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
相关优秀博文
http://blog.jobbole.com/78960/
http://my.oschina.net/u/877348/blog/152660