Preparing the working environment
Overview¶
In the following, we prepare our working environment to properly use Git from the shell.
Tips for instructors
- Please note that it might be the first time for some participants that they use a shell. For that reason, please allow them to get a bit used to work with the shell.
Checkpoints:
- Please make sure that everyone could open the shell.
- Please make sure that everyone has set up the environment successfully.
Open a shell¶
A shell (also known as: terminal, command line, console) is a program which allows you to run commands on your computer and to receive their output. We use Git from the shell because it clearer shows the way how Git works.
- Some computers offer a default UNIX shell.
Please open it on your computer:
- Windows: Windows does not offer a default UNIX shell but you can use the Git Bash shell included with
Git for Windows
. Please open it via a right-click on your Desktop and selectingOpen Git Bash here
. - MacOS: You have a Bash or a Zsh shell available depending on your MacOS version.
Please open it, for example, by searching
Terminal
via the MacOS search functionality. - Linux: The default shell is usually Bash.
It is often accessible via the Gnome Terminal, the KDE Konsole or xterm.
Please open it by using the applications menu or the search bar.
- Windows: Windows does not offer a default UNIX shell but you can use the Git Bash shell included with
- Your shell has been opened in a specific directory.
You can check the location by typing the command
pwd
: In this case, the shell has been opened in the home directory of a specific user. Please double-check that you are in the right directory.
Prepare your working environment¶
In the following, we prepare our working environment and try out other useful shell commands:
- Please open your local file browser and switch to the directory in which you are in your shell.
ls
- This command shows the content (directories and files) of the current directory.- The
ls
command can be executed with a number of options:ls -l -a total 8 drwxr-xr-x 1 user group 0 Sep 2 16:32 ./ drwxr-xr-x 1 user group 0 Aug 29 14:41 ../ drwxr-xr-x 1 user group 0 Sep 2 16:32 input/
-l
: Shows a more comprehensive overview of the current directory including information such as permissions, the last modification date and time, etc..-a
: Shows hidden directories and files (i.e., names start with.
) as well. In this case, it adds the special directory references./
(refers to the current directory) and../
(refers to the parent directory).
mkdir workshop
- Creates a new, empty directory namedworkshop
in the current directory. We use this directory to store our local Git repositories later.cd workshop
- We switch into the newly created directory. Please switch into the directory via your file browser as well.touch test.txt
- We create an empty filetest.txt
. If you “touch” an existing file, the command will only update the last modification date and time.- Please open the file
test.txt
in your favorite text file editor, add the contentHello Git/GitLab workshop audience!
and save the file. less test.txt
- Shows the file content oftest.txt
and allows scrolling via the Up and the Down keys. You can quit this view with the help of the Q key. Git also makes use of the command when showing longer output.rm test.txt
- Permanently deletes the filetext.txt
. Please be careful because you cannot (easily) undo deletions viarm
!
Additional tips
- No news are good news: Commands which ran without output, usually worked as intended.
<command> --help
: For most commands, this option produces a (short) help message on how to use the command.- With the Tab key, file names can be auto-completed.
- On Windows, Ctrl+C / Ctrl+V for copying text form / pasting text to the shell might not work.
Please use Right Button of your mouse in the shell and select
Copy
orPaste
instead.
Key points¶
At the end you should have prepared the following:
- Opened a shell from which we later run the Git commands.
- Switched into the created
workshop
directory. - Prepared the other tools such as your file browser and editor.