官术网_书友最值得收藏!

Creating a new branch

Now that we have warmed up, the fun begins. Let's see what happens when you ask Git to create a new branch. Since we are going to serve a delicious fruit salad, it's time to set a branch apart for a berries-flavored variant recipe:

[9] ~/grocery (master)
$ git branch berries

That's all! To create a new branch, all you need to do is call the git branch followed by the name of the branch you'd like to use. And this is super-fast; always working locally, Git does this kind of work in a blink of an eye.

To be true, there are some (complicated) rules to be respected and things to know about the possible name of a branch (all you need to know is here: https://git-scm.com/docs/git-check-ref-format), but for now it is not relevant.

So, git log again:

[10] ~/grocery (master)
$ git log --oneline --graph --decorate
* 0e8b5cf (HEAD -> master, berries) Add an orange
* e4a5e7b Add an apple
* a57d783 Add a banana to the shopping list

Wonderful! Now Git tells us there's a new branch, berries, and it refers to the same commit as a master branch.

Anyway, at the moment we continue to be located in the master branch; in fact, as you can see in the shell output prompt, it continues to appear (master) between the round parenthesis:

[10] ~/grocery (master)

How can I switch branch? By using the git checkout command:

[11] ~/grocery (master)
$ git checkout berries
Switched to branch 'berries'

Do a git log to see:

[12] ~/grocery (berries)
$ git log --oneline --graph --decorate
* 0e8b5cf (HEAD -> berries, master) Add an orange
* e4a5e7b Add an apple
* a57d783 Add a banana to the shopping list

Mmm, interesting! Now there's a (berries) sign into the shell prompt, and more, something happened to that HEAD thing: now the arrows points to berries, not more to master. What does it mean?

主站蜘蛛池模板: 仁怀市| 钟祥市| 扶余县| 敦化市| 璧山县| 清水县| 平邑县| 葫芦岛市| 纳雍县| 潞城市| 美姑县| 通化市| 岗巴县| 聂荣县| 洞头县| 祁连县| 乌什县| 铁岭县| 饶平县| 浏阳市| 盱眙县| 冷水江市| 安丘市| 汪清县| 颍上县| 仙居县| 绍兴市| 固阳县| 康保县| 卢氏县| 锦州市| 通州区| 长治县| 贺州市| 东辽县| 九寨沟县| 重庆市| 石门县| 文昌市| 招远市| 岗巴县|