Creating and Switching Git Branches[Make a record]

  1. Check my current branch:
$ git branch


The content of readme.md:

  1. I use the $ git checkout -b dev to create a branch and switch to it:

The command $ git checkout -b dev is the same as the following two commands' integration:

$ git branch dev
$ git checkout dev
  1. Check my current branch again:


    There is a * before the name of current branch.

  2. Then I add Creating a new branch is quick. in my local test => readme.md

  3. Check the status and operate the following command to commit the modified readme.md:

$ git add readme.md
$ git commit -m "branch test"

I add emoji here, $ git commit -m ":memo: branch test"

  1. After these operation, I re-switch to master branch and check the local test => readme.md, find that the change I made has disappeared.

Because the change I made is on the dev branch, not the master branch. So I can't see it in current readme.md.

  1. Now, merge the changes of dev to master branch:
$ git merge dev


And then look at the local readme.md:

The changes appear again~

  1. Push the change to the remote repository:
$ git push

  1. And now, I can delete the dev branch:
$ git branch -d dev

After deletion, check the current branch, that is only master branch.

  1. Commands:

Check branches:git branch

Create a new branch:git branch <name>

Switch branches:git checkout <name>

Create+Switch branches:git checkout -b <name>

Merge branches:git merge <name>

Delete branches:git branch -d <name>


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,449评论 0 10
  • 银闪付推广奖励政策: 分享给朋友注册就有实时返现:奖励0.2元; 注册用户实名认证后再返现:奖励0.5元; 该商户...
    5452e382e782阅读 989评论 0 0
  • 下班了,想回家躺在床上好好的睡上一觉,但是好多事情都没有做,一想到马|上就是月底了,财务上一些事情不处理,拖一个月...
    谢其国阅读 129评论 0 1
  • 作者:祝桂丽(岁月如歌) 都说雨天 适合思念 风中斟酌了一番 惦念在窖藏 是否该让醇意随风飘远 岁月附在耳旁 说了...
    尘世低眉阅读 213评论 5 14