mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2025-05-01 20:42:01 +02:00
Polish branches chapter
This commit is contained in:
parent
80c50bdc81
commit
be45b82e41
18 changed files with 231 additions and 191 deletions
|
@ -1,35 +1,40 @@
|
|||
title = Party Time
|
||||
cards = checkout commit-auto reset-hard branch
|
||||
title = Creating branches
|
||||
cards = checkout commit-auto branch branch-delete reset-hard
|
||||
|
||||
[description]
|
||||
|
||||
You were invited to two parties but they will happen at the same time! At party 1 your favorite band is playing and the other one is your best friend's birthday party.
|
||||
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!
|
||||
|
||||
Where should you go? No worries - you are a time travel agent in training. You can go to both parties! To quickly switch between both events, check out the last commits and
|
||||
create branches with the `git branch [string]` command. Now you can easily switch between both branches by calling `git checkout [branch]`.
|
||||
To make it easier to tell which timeline is which, you can create time portals! (We call these "branches".)
|
||||
|
||||
[setup]
|
||||
|
||||
echo "-Birthday present.
|
||||
-Concert ticket." > backpack
|
||||
echo "You wrap the birthday present, and grab your concert ticket." > you
|
||||
git add .
|
||||
git commit -m "evening preparations"
|
||||
echo "-Birthday present." > backpack
|
||||
git commit -m "Evening preparations"
|
||||
echo "You go to the birthday party!" >> you
|
||||
git add .
|
||||
git commit -m "go to the birthday"
|
||||
git commit -m "Go to the birthday"
|
||||
|
||||
git checkout HEAD~1
|
||||
echo "-Concert ticket." > backpack
|
||||
echo "You go to the concert!" > you
|
||||
git add .
|
||||
git commit -m "go to the concert"
|
||||
git commit -m "Go to the concert"
|
||||
|
||||
git checkout HEAD~1
|
||||
|
||||
git branch -D main
|
||||
|
||||
[win]
|
||||
|
||||
NUM_BRANCHES="$(git show-ref --heads | wc -l)"
|
||||
test "$NUM_BRANCHES" -ge 3
|
||||
# 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'
|
||||
|
||||
[congrats]
|
||||
|
||||
Now you can travel between those branches easily (using `git checkout`) - try it!
|
||||
|
||||
Your friend is happy that you made it to the birthday party and you also got your concert ticket signed. Yay!
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
title = Choose your own adventure
|
||||
title = Deleting branches
|
||||
cards = checkout commit-auto reset-hard branch-delete
|
||||
|
||||
[description]
|
||||
|
@ -7,8 +7,6 @@ Life is full of dangers, right? Even when walking to school, it seems like there
|
|||
|
||||
This Monday is especially bad. You made it to school, but there's some timelines you definitely don't want to keep around.
|
||||
|
||||
Find the bad branches and delete them. Keep the one that seems okay.
|
||||
|
||||
[setup]
|
||||
|
||||
echo You leave your house and start walking to school. > you
|
||||
|
@ -33,14 +31,16 @@ echo Because you\'re kind of late, you start running. Someone throws a piano out
|
|||
git commit -am "Sounds nice"
|
||||
|
||||
git checkout HEAD^ -b ice-cream
|
||||
echo You\'re not in a hurry, and walk slowly. You even get some ice cream on your way. You arrive at school too late, and your teacher is angry. >> you
|
||||
echo You\'re not in a hurry, and walk slowly. You even get some ice cream on your way. You arrive at school too late, your teacher is angry, and you are expelled. >> you
|
||||
git commit -am "Yum"
|
||||
|
||||
git checkout main
|
||||
git branch -M main leap
|
||||
git checkout leap^^
|
||||
|
||||
[win]
|
||||
|
||||
test "$(git branch | cut -c 3-)" = "$(echo -e ice-cream\\nmain)"
|
||||
# Find the bad branches and delete them. Keep the best one.
|
||||
test "$(git show-ref --heads | cut -f2 -d' ')" = "$(echo refs/heads/leap)"
|
||||
|
||||
[congrats]
|
||||
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
title = Branching out
|
||||
cards = checkout commit-auto merge reset-hard
|
||||
|
||||
[description]
|
||||
|
||||
You can use these little blue labels to give names to different timelines! This makes it easier to remember what happened where.
|
||||
|
||||
One of your colleagues messed up here - can you help reordering the branches correctly using the "reset" card?
|
||||
|
||||
When you do commits or merges while you're on a branch, the branch will grow with you. Try that while you eat that donut.
|
||||
|
||||
Finally, merge all timelines together, in a way so that the "main" branch points to the result. That's base reality!
|
||||
|
||||
---
|
||||
tipp1
|
||||
---
|
||||
tipp2
|
||||
---
|
||||
tipp3
|
||||
|
||||
[setup]
|
||||
|
||||
echo "A friendly old lady.
|
||||
Sells delicious baguettes." > mary
|
||||
|
||||
echo "A rebellious teenager.
|
||||
Sells good coffee." > larry
|
||||
|
||||
echo "A snail. Literally a snail.
|
||||
Sells donuts with an unspecified, slimy filling." > gary
|
||||
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
|
||||
git add .
|
||||
git commit -m "The Beginning"
|
||||
|
||||
git checkout -b coffee
|
||||
echo "You have a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You buy a baguette"
|
||||
|
||||
echo "You ate a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You eat the baguette"
|
||||
|
||||
git checkout -b baguette main
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You buy some coffee"
|
||||
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You drank coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You drink the coffee"
|
||||
|
||||
git checkout -b donut main
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You have a donut." > you
|
||||
git add .
|
||||
git commit -m "You buy a donut"
|
||||
|
||||
git checkout --detach main
|
||||
|
||||
[win]
|
||||
|
||||
# Did you eat a baguette on the main branch?
|
||||
git show main:you | grep "You ate.*baguette"
|
||||
|
||||
# Did you drink a coffee on the main branch?
|
||||
git show main:you | grep "You drank.*coffee"
|
||||
|
||||
# Did you eat a donut on the main branch?
|
||||
git show main:you | grep "You ate.*donut"
|
||||
|
||||
[actions]
|
||||
|
||||
test "$(git rev-parse HEAD^)" = "$(git rev-parse donut)" && hint "Ooops, your branch ref is still on the old commit."
|
||||
|
||||
[congrats]
|
||||
|
||||
Nice! It's often convenient to stay on branches most of the time!
|
39
levels/branches/checkout-commit
Normal file
39
levels/branches/checkout-commit
Normal file
|
@ -0,0 +1,39 @@
|
|||
title = Moving through time
|
||||
cards = checkout commit-auto
|
||||
|
||||
[description]
|
||||
|
||||
The yellow boxes are frozen points in time, we call them "commits"! You can travel between them using the "checkout" card! (Try it!)
|
||||
|
||||
The grey panel below shows your current environment - click on an object to inspect or modify it!
|
||||
|
||||
Can you find out what happened here? Then, while on the latest commit, fix the problem, and make a new commit!
|
||||
|
||||
[setup]
|
||||
|
||||
echo "This piggy bank belongs to the big sister.
|
||||
It contains 10 coins." > piggy_bank
|
||||
git add .
|
||||
git commit -m "The beginning"
|
||||
|
||||
echo "A young girl with brown, curly hair." > little_sister
|
||||
git add .
|
||||
git commit -m "Little sister comes in"
|
||||
|
||||
echo "Has 10 coins." >> little_sister
|
||||
echo "This piggy bank belongs to the big sister.
|
||||
It is empty." > piggy_bank
|
||||
git add .
|
||||
git commit -m "Little sister does something"
|
||||
|
||||
git checkout HEAD^^
|
||||
git branch -df main
|
||||
|
||||
[win]
|
||||
|
||||
# Restore sisterly peace.
|
||||
{ git show HEAD:piggy_bank | grep "10 coins"; } && { git show HEAD:little_sister | grep -v "10 coins"; } && { git rev-parse HEAD^^^; }
|
||||
|
||||
[congrats]
|
||||
|
||||
Wonderful! Now that you're getting familiar with the time machine, let's look at some more complicated situations...
|
|
@ -1,4 +1,4 @@
|
|||
title = Parallelism
|
||||
title = Make parallel commits
|
||||
cards = checkout commit-auto
|
||||
|
||||
[description]
|
||||
|
@ -38,10 +38,10 @@ git branch -d main
|
|||
|
||||
[win]
|
||||
|
||||
# Is the child still there?
|
||||
# Make sure that the child is happy.
|
||||
git ls-tree --name-only -r HEAD | grep child
|
||||
|
||||
# Is the lion not hungry?
|
||||
# Make sure that the lion gets something to eat.
|
||||
git show HEAD:cage/lion | grep -v "very hungry"
|
||||
|
||||
[congrats]
|
45
levels/branches/grow
Normal file
45
levels/branches/grow
Normal file
|
@ -0,0 +1,45 @@
|
|||
title = Branches grow with you!
|
||||
cards = checkout commit-auto branch branch-delete reset-hard
|
||||
|
||||
[description]
|
||||
|
||||
Note that there are two options to "travel to the end of a timeline":
|
||||
|
||||
First, you can directly travel to the commit, like we've done it before.
|
||||
|
||||
And second, you can travel to the branch label. In this case, when you make a new commit, the branch will grow with you, and still point at the end of the timeline, which is usually what we want!
|
||||
|
||||
Let's try both of these!
|
||||
|
||||
[setup]
|
||||
|
||||
echo "You wrap the birthday present, and grab your concert ticket." > you
|
||||
git add .
|
||||
git commit -m "Evening preparations"
|
||||
echo "You go to the birthday party!" >> you
|
||||
git add .
|
||||
git commit -m "Go to the birthday"
|
||||
git branch birthday
|
||||
|
||||
git checkout HEAD~1
|
||||
echo "You go to the concert!" > you
|
||||
git add .
|
||||
git commit -m "Go to the concert"
|
||||
git branch concert
|
||||
|
||||
git checkout HEAD~1
|
||||
|
||||
git branch -D main
|
||||
|
||||
[win]
|
||||
|
||||
# Travel directly to the last commit of the birthday timeline, make a change to 'you', and make a commit
|
||||
for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do
|
||||
if test $(git rev-parse $commit^) = $(git rev-parse birthday); then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
|
||||
# Travel to the 'concert' branch, make a change to 'you', and a commit.
|
||||
git show concert^ | grep "Go to the concert"
|
81
levels/branches/reorder
Normal file
81
levels/branches/reorder
Normal file
|
@ -0,0 +1,81 @@
|
|||
title = Moving branches around
|
||||
cards = checkout commit-auto merge reset-hard
|
||||
|
||||
[description]
|
||||
|
||||
One of your colleagues messed up here, and put the branches in the wrong timelines!
|
||||
|
||||
You could delete and re-create these branches - but you can also directly move them to different commits, using `git reset --hard`.
|
||||
|
||||
The donut branch is in the right place, but the timeline is still incomplete.
|
||||
|
||||
[setup]
|
||||
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
|
||||
git add .
|
||||
git commit -m "The Beginning"
|
||||
|
||||
git checkout -b coffee
|
||||
echo "You have a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You buy a baguette"
|
||||
|
||||
echo "You ate a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You eat the baguette"
|
||||
|
||||
git checkout -b baguette main
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You have coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You buy some coffee"
|
||||
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You drank coffee.
|
||||
|
||||
You do not have a donut." > you
|
||||
git add .
|
||||
git commit -m "You drink the coffee"
|
||||
|
||||
git checkout -b donut main
|
||||
echo "You do not have a baguette.
|
||||
|
||||
You do not have coffee.
|
||||
|
||||
You have a donut." > you
|
||||
git add .
|
||||
git commit -m "You buy a donut"
|
||||
|
||||
git checkout --detach main
|
||||
|
||||
[win]
|
||||
|
||||
# Did you eat a baguette on the baguette branch?
|
||||
git show baguette:you | grep "You ate.*baguette"
|
||||
|
||||
# Did you drink a coffee on the coffee branch?
|
||||
git show coffee:you | grep "You drank.*coffee"
|
||||
|
||||
# Did you eat a donut on the donut branch?
|
||||
git show donut:you | grep "You ate.*donut"
|
||||
|
||||
[actions]
|
||||
|
||||
test "$(git rev-parse HEAD^)" = "$(git rev-parse donut)" && hint "Remember to checkout the blue branch tag when you want it to grow with the timeline."
|
6
levels/branches/sequence
Normal file
6
levels/branches/sequence
Normal file
|
@ -0,0 +1,6 @@
|
|||
checkout-commit
|
||||
fork
|
||||
branch-create
|
||||
grow
|
||||
branch-remove
|
||||
reorder
|
Loading…
Add table
Add a link
Reference in a new issue