Creating and Switching Git Branches[Make a record]

  1. Check my current branch:
$ git branch


The content of readme.md:

Creating and Switching Git Branches[Make a record]_第1张图片
  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

    Creating and Switching Git Branches[Make a record]_第2张图片

  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"

Creating and Switching Git Branches[Make a record]_第3张图片

  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.
    Creating and Switching Git Branches[Make a record]_第4张图片

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

Creating and Switching Git Branches[Make a record]_第5张图片

And then look at the local readme.md:
Creating and Switching Git Branches[Make a record]_第6张图片

The changes appear again~

  1. Push the change to the remote repository:
$ git push
Creating and Switching Git Branches[Make a record]_第7张图片

  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

Switch branches:git checkout

Create+Switch branches:git checkout -b

Merge branches:git merge

Delete branches:git branch -d


Creating and Switching Git Branches[Make a record]_第8张图片

你可能感兴趣的:(Creating and Switching Git Branches[Make a record])