git仓库的基本操作
2015-11-09 14:24
239 查看
1.创建仓库
git init 一般创建本地仓库使用
git init - -bare 初始化裸仓库,服务器上残酷推荐建立裸仓库,不能执行一些基本的git操作
2. 拷贝远程仓库
git clone [仓库地址] -b [远程分支名称](可选)
clone之后,git会讲远程仓库的名称用别名 origin 表示
3. git add
git commit
git push origin [本地分支名称]
比如: git push origin branch-test ( branch-test为本地分支名称)
origin只相当于一个别名,代表的是远程的仓库,不是分支。运行git remote –v或者查看.git/config可以看到origin的含义
git push 的完整语法为: git push [<repository>] [<refspec......>]
repository 为远程仓库, 上面的例子中为: origin
refspec.... 为分支信息 +<src>:<dst> src为本地分支。dst为远程分支。 git push origin master中省略了 dst。默认时和local branch名字一样。
4. 创建分支
创建本地分支
git branch [local name] 跟踪默认的远程分支
git branch[local name] [remote name] 创建跟踪指定远程分支的本地分支
删除本地分支
git branch -D [本地分支名称]
创建远程分支
git push origin[本地分支名称] (将本地分支推送到远程分支,也就创建了远程)
删除远程分支
git push origin :[远程分支名称]
git push origin :refs/for/test-remote (:test-remote为远程分支)注意分号的位置
参考:Git 的origin和master分析
master其实是一个“refspec”,正常的“refspec”的形式为”+<src>:<dst>”,冒号前表示local
branch的名字,冒号后表示remote repository下 branch的名字。注意,如果你省略了<dst>,git就认为你想push到remote
repository下和local branch相同名字的branch。听起来有点拗口,再解释下,push是怎么个push法,就是把本地branch指向的commit
push到remote repository下的branch,比如:
$git push origin master:master (在local repository中找到名字为master的branch,使用它去更新remote
repository下名字为master的branch,如果remote repository下不存在名字是master的branch,那么新建一个)
$git push origin master (省略了<dst>,等价于“git push origin master:master”)
$git push origin master:refs/for/mybranch (在local repository中找到名字为master的branch,用他去更新remote
repository下面名字为mybranch的branch)
$git push origin HEAD:refs/for/mybranch
(HEAD指向当前工作的branch,master不一定指向当前工作的branch,所以我觉得用HEAD还比master好些)
$git push origin :mybranch (再origin repository里面查找mybranch,删除它。用一个空的去更新它,就相当于删除了)
git init 一般创建本地仓库使用
git init - -bare 初始化裸仓库,服务器上残酷推荐建立裸仓库,不能执行一些基本的git操作
2. 拷贝远程仓库
git clone [仓库地址] -b [远程分支名称](可选)
clone之后,git会讲远程仓库的名称用别名 origin 表示
3. git add
git commit
git push origin [本地分支名称]
比如: git push origin branch-test ( branch-test为本地分支名称)
origin只相当于一个别名,代表的是远程的仓库,不是分支。运行git remote –v或者查看.git/config可以看到origin的含义
git push 的完整语法为: git push [<repository>] [<refspec......>]
repository 为远程仓库, 上面的例子中为: origin
refspec.... 为分支信息 +<src>:<dst> src为本地分支。dst为远程分支。 git push origin master中省略了 dst。默认时和local branch名字一样。
4. 创建分支
创建本地分支
git branch [local name] 跟踪默认的远程分支
git branch[local name] [remote name] 创建跟踪指定远程分支的本地分支
删除本地分支
git branch -D [本地分支名称]
创建远程分支
git push origin[本地分支名称] (将本地分支推送到远程分支,也就创建了远程)
删除远程分支
git push origin :[远程分支名称]
git push origin :refs/for/test-remote (:test-remote为远程分支)注意分号的位置
参考:Git 的origin和master分析
master其实是一个“refspec”,正常的“refspec”的形式为”+<src>:<dst>”,冒号前表示local
branch的名字,冒号后表示remote repository下 branch的名字。注意,如果你省略了<dst>,git就认为你想push到remote
repository下和local branch相同名字的branch。听起来有点拗口,再解释下,push是怎么个push法,就是把本地branch指向的commit
push到remote repository下的branch,比如:
$git push origin master:master (在local repository中找到名字为master的branch,使用它去更新remote
repository下名字为master的branch,如果remote repository下不存在名字是master的branch,那么新建一个)
$git push origin master (省略了<dst>,等价于“git push origin master:master”)
$git push origin master:refs/for/mybranch (在local repository中找到名字为master的branch,用他去更新remote
repository下面名字为mybranch的branch)
$git push origin HEAD:refs/for/mybranch
(HEAD指向当前工作的branch,master不一定指向当前工作的branch,所以我觉得用HEAD还比master好些)
$git push origin :mybranch (再origin repository里面查找mybranch,删除它。用一个空的去更新它,就相当于删除了)
相关文章推荐
- Jecc(java椭圆曲线加密库)学习笔记及ECDH实现
- 数据标准化的几种方法
- 压缩VBox虚拟机空间的方法
- Linux 下载工具 aria2
- 服务器硬盘分区只读监控
- android JIN详解
- Google Java编程风格指南中文版
- return 开发时新的
- 软件开发资源
- 最快的Json框架-Jfire-codejson解析
- 64位Redhat6.6未注册 ,yum改成 CentOS6.6 的方法
- centos下修改hostname,ip,netmask,gateway,dns
- poj1573模拟法
- OpenGL ES(4)——使用投影和Camera Views
- Codis作者黄东旭细说分布式Redis架构设计和踩过的那些坑
- 利用doxygen生成python文档
- VMware虚拟机上网络连接(network type)的三种模式--bridged、host-only、NAT
- UIlabel 属性text
- 不当词语检测器
- EXT menu