- Check my current branch:
$ git branch

The content of
readme.md
:

- 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
-
Check my current branch again:
There is a*
before the name of current branch. -
Then I add
Creating a new branch is quick.
in my localtest => readme.md
-
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"

- After these operation, I re-switch to
master
branch and check the localtest => 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
.
- Now, merge the changes of
dev
tomaster
branch:
$ git merge dev

And then look at the local
readme.md
:
The changes appear again~
- Push the change to the remote repository:
$ git push


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

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

- 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>

网友评论