Creating and Switching Git Branc

2018-04-25  本文已影响0人  yilinUnique
  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>


上一篇下一篇

猜你喜欢

热点阅读