Exercise - The git command!

In the first exercise, the goal is to get to know the (Git) Bash command line and especially the git command.

Tips

  • For Windows users:
    • Use the Git-Bash command line, then you can run examples exactly as shown here.
    • Use ‘/’ instead of ‘' for directory paths.
    • If you are working with the Windows command line CMD, you may need to make minor changes for the examples to work.
  • Bash commands
    • cd <directoryname>, changes to another directory.
    • cd .., changes to the parent directory. One level up!
    • ls shows the names of the files and subdirectories in the current directory.
    • ll Like ls but with more details.
    • less. Display the content of a file. Scroll with arrow keys. Quit with the q key.
    • pwd shows the current working directory. On Windows: pwd -W (uppercase)
  • Git commands
    • git version shows which version of Git is installed.
    • git help <command> shows help.
    • git config <property> shows the value from the configuration.
    • git config set --global <property> <new-value> sets a value in the configuration.
    • git config core.editor notepad configures Notepad as the editor for Git.
    • If the output has more lines than the terminal window is high, the output is displayed in a viewer (less). You can then scroll up and down with the arrow keys. You exit the less mode with the q key.
  • Command start <file> (Ubuntu: xdg-open, Mac Os: open) opens the specified file with the associated default application. start . opens the file explorer in the current directory.

Short intro to the command line

Step 0 - START

Step 1 - Navigation in exercise directories

Start in directory git-uebungen.

(from the unzipped zip file)

Navigate to the subdirectory aufgaben/intro-commandline/hallo and look at the content of the file located there. Use tab completion to avoid typing so much. Then navigate back to the parent directory intro-commandline.

Step 2 - Check Git version

Start in directory git-uebungen/aufgaben/<unknown>.

Print which version of Git is installed.

Step 3 - Help

Start in directory git-uebungen/aufgaben/<unknown>.

Show the help page for the log command.

$ cd repo


Step 4 - `less` and long outputs

Start in directory git-uebungen/aufgaben/<unknown>.

When you run git log, 99 commits should be displayed. Because this does not fit in a terminal window, the less viewer is opened. Close it. Then use less some-file.txt to view a file in less mode.

Step 5 - Configure Git

Start in directory git-uebungen/aufgaben/<unknown>.

Check the user configuration:

$ git config user.name
$ git config user.email
$ git config pull.rebase
$ git config merge.conflictStyle
$ git config --global init.defaultBranch

Configure your username and email, if not already set:

$ git config --global user.name my-name
$ git config --global user.email my-email

The following configurations were used when recording the sample solution. It is recommended to set them for this workshop:

$ git config --global pull.rebase false
$ git config --global merge.conflictStyle diff3
$ git config --global init.defaultBranch main

Step 6 - ⭐ History

Start in directory git-uebungen/aufgaben/<unknown>.

Press the 🡅 key several times and then press enter, to execute one of the previous commands again. Type ctrl+r and then enter conflict, to re-run the command to set merge.conflictStyle.

Step 7 - ⭐ Configure Git editor

Start in directory git-uebungen/aufgaben/<unknown>.

Configure an editor for git. Tips on this.f Then test with git config -e to see if it worked.

Step 8 - ⭐ Working directory

Start in directory git-uebungen/aufgaben/<unknown>.

Print out which working directory you are currently in. For Windows users: also test the command with the -W option.

Step 9 - ⭐ Open applications

Start in directory git-uebungen/aufgaben/<unknown>.

Open the file some-file.txt with the default application. Open a file explorer in the current working directory.

repo $ cd ..


To the solution

To the overview