Git Workshop
POSTS

Introduction

Alice and Bob are writers who are collaborating on a new book. They’ve decided to use Git as their tool for collaborative edition, and a very ancient computer with a model M keyboard attached to it.

Model M keyboard

To get started, they’ll need to set up a Git repository for the book. This will allow them to track changes to the book over time, collaborate on the book together, and easily merge their changes into a single version of the book.

Note: this tutorial assumes you have access to both git and ed commands. If it is not true, feel free to install them:

sudo apt update
sudo apt install -y git ed

About ed

ed is the original Unix editor. It is a sophisticated piece of software that will help us to manipulate text files in a precise way.

It can be used both programmatically and with an interactive shell, but mostly we will take advantage of its automation characteristics to update the content of the book.

For example, this script will insert a message in the line number two of the example.txt file, write the updated file on disk and quit from ed:

ed example.txt << EOF
2i
This text will be inserted on line number two.
.
w
q
EOF

Exercise

This exercise contains the solution hidden on it. We are going to use this format during the training: invest some time trying to solve the proposed problem, and ask for support to your trainer if you get lock. But, in case of desperation, you can always click on the Show solution button to get a tip or even the whole answer… after a few minutes of having started to solve it ;)

Now that we are familiar with the format, **let's solve our first challenge**:

We are going to practice with the ed command. Start by creating a file:

cat << EOF > myfile.txt
aaaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
EOF

cat myfile.txt

Now, use what you have learnt to insert a line of 0 (zeros) between all those bbbbbbbbbbb and ccccccccccc. Remember: ed is a line-based text editor.

Hint:

ed myfile.txt << EOF
█i
00000000000
.
█
█
EOF

Solution:

ed myfile.txt << EOF
3i
00000000000
.
w
q
EOF

cat myfile.txt

    Quick access

    1. Introduction
    2. Alice: repo initialization
    3. Alice: first commits
    4. Alice: moving through the timeline
    5. Alice: basic branching
    6. Alice: merging without conflicts
    7. Alice: merging with conflict resolution
    8. Alice: tagging
    9. Bob: cloning repositories
    10. Bob: pushing to origin
    11. Alice: merging and log format
    12. Alice: centralized repository creation
    13. Bob: pulling
    14. Bob: recovering from errors with the reference log
    15. Bob finds the author of a typo
    16. Alice: amending commits
    17. Alice: history simplification
    18. Alice: cherry picking changesets
    © Git Workshop 2023