oh-my-git/levels/branches/branch-create

45 lines
1.4 KiB
Text
Raw Permalink Normal View History

2021-01-13 16:26:48 +01:00
title = Creating branches
cards = checkout commit-auto branch branch-delete reset-hard
2020-11-13 12:23:14 +01:00
[description]
2021-01-13 16:26:48 +01:00
You were invited to two parties! At one of them, your favorite band is playing - and the other one is your best friend's birthday party. Where should you go? No worries - as a time travel agent in training, you can go to both parties!
2020-11-13 12:23:14 +01:00
2021-01-13 16:26:48 +01:00
To make it easier to tell which timeline is which, you can create time portals! (We call these "branches".)
2020-11-13 12:23:14 +01:00
[cli]
Branches also make it really easy to travel between different places using the command line! As soon as you have a branch called "birthday", you can type `git checkout birthday` to travel to it!
2020-11-13 12:23:14 +01:00
[setup]
2021-01-13 16:26:48 +01:00
echo "You wrap the birthday present, and grab your concert ticket." > you
2020-11-13 12:23:14 +01:00
git add .
2021-01-13 16:26:48 +01:00
git commit -m "Evening preparations"
echo "You go to the birthday party!" >> you
2020-11-13 12:23:14 +01:00
git add .
2021-01-13 16:26:48 +01:00
git commit -m "Go to the birthday"
2020-11-13 12:23:14 +01:00
git checkout HEAD~1
2021-01-13 16:26:48 +01:00
echo "You go to the concert!" > you
2020-11-13 12:23:14 +01:00
git add .
2021-01-13 16:26:48 +01:00
git commit -m "Go to the concert"
2020-11-13 12:23:14 +01:00
git checkout HEAD~1
2021-01-13 16:26:48 +01:00
git branch -D main
2020-11-13 12:23:14 +01:00
[win]
2021-01-13 16:26:48 +01:00
# Create a branch called 'birthday' that points to the birthday timeline.
git show birthday | grep 'to the birthday'
# Create a branch called 'concert' that points to the concert timeline.
git show concert | grep 'to the concert'
2020-11-13 12:23:14 +01:00
[congrats]
2021-01-13 16:26:48 +01:00
Now you can travel between those branches easily (using `git checkout`) - try it!
2020-11-13 12:23:14 +01:00
Your friend is happy that you made it to the birthday party and you also got your concert ticket signed. Yay!