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

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?

主站蜘蛛池模板: 柞水县| 股票| 孝感市| 含山县| 余姚市| 玉田县| 淮北市| 兴隆县| 鲁甸县| 霍林郭勒市| 迁西县| 临海市| 池州市| 白玉县| 越西县| 荣昌县| 承德县| 郸城县| 高碑店市| 松江区| 毕节市| 三都| 无为县| 威宁| 蛟河市| 安乡县| 山阴县| 仙居县| 和政县| 罗定市| 邵武市| 安徽省| 漯河市| 防城港市| 晋江市| 巩义市| 沭阳县| 大丰市| 庆元县| 五河县| 禄劝|