Git usage Summary

Source: Internet
Author: User

I. Remote repository with master and Dev branches
1. Cloning code
git clone https://github.com/master-dev.git  # 这个git路径是无效的,示例而已
2. View all Branches
git branch --all  # 默认有了dev和master分支,所以会看到如下三个分支# master[本地主分支] origin/master[远程主分支] origin/dev[远程开发分支]# 新克隆下来的代码默认master和origin/master是关联的,也就是他们的代码保持同步# 但是origin/dev分支在本地没有任何的关联,所以我们无法在那里开发
3. Create a branch of the locally associated Origin/dev
git checkout dev origin/dev  # 创建本地分支dev,并且和远程origin/dev分支关联,本地dev分支的初始代码和远程的dev分支代码一样
git branch dev  # 创建本地分支git branch  # 查看分支# 这是会看到master和dev,而且master上会有一个星号# 这个时候dev是一个本地分支,远程仓库不知道它的存在
# 本地分支可以不同步到远程仓库,我们可以在dev开发,然后merge到master,使用master同步代码,当然也可以同步
4. Release the Dev Branch
Publishing Dev branch refers to the code that synchronizes the dev branch to the remote server
git push origin dev:dev  # 这样远程仓库也有一个dev分支了
5. Developing code in Dev branch
git checkout dev  # 切换到dev分支进行开发# 开发代码之后,我们有两个选择# 第一个:如果功能开发完成了,可以合并主分支git checkout master  # 切换到主分支git merge dev  # 把dev分支的更改和master合并git push  # 提交主分支代码远程git checkout dev  # 切换到dev远程分支git push  # 提交dev分支到远程# 第二个:如果功能没有完成,可以直接推送git push  # 提交到dev远程分支# 注意:在分支切换之前最好先commit全部的改变,除非你真的知道自己在做什么
6. Delete a branch
git push origin :dev  # 删除远程dev分支,危险命令哦# 下面两条是删除本地分支git checkout master  # 切换到master分支git branch -d dev  # 删除本地dev分支
Color
Links: http://www.zhihu.com/question/21995370/answer/19975870
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Git usage Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.