Shell & Git
About this Document
This document contains the basic aspects of a workshop the student council offers to new cs students.
Reading this Document
- CAVEAT
- A common mistake or error in reasoning to avoid
- Remark
- More advanced knowledge
- Unikn
- A comment on university-specific aspects
Unikn: Getting Started
Internet Access
Make sure you have a working internet connection.
On campus this means eduroam wifi. Follow the
instructions here
to get access. Ask “KIM Beratung” for help right at the
entrance of the library if there are any issues.
Gaining internet access should be one of the first things you do on campus.
Access to University Servers
There are two relevant university servers for you:
- Gitlab for git repos (more on that below)
titan07.inf.uni-konstanz.defor a working shell
CAVEAT: Are you not majoring in CS?
You are welcome to attend any of the workshops we offer. However, to fully gain access to the servers above you may need to send an email from your university mail account to
syst@inf.uni-konstanz.dewith the subjectsubscribe. This should give you access to the servers above within about five minutes.
SSH into titan
If you don’t have an environment to play with the commands introduced below, you can use this server. It also comes with git preinstalled.
To access it we use ssh, a command to open a shell on a remote server. Using ssh differs a bit between operating systems, the most prominent ones are listed below. Please attend the workshop or “Schlüsselkompetenzen der Informatik” if you need help.
All Operating Systems: POP ID
For technical reasons you CANNOT login to the titan server with your
usual “firstname.lastname” credentials. You have to find your pop_id and
substitute it for pop_id in the commands listed for your operating system
below.
- Open https://www.kim.uni-konstanz.de/services/konten-und-passwoerter/
- Click on Uni-Account
- Login in with your “firstname.lastname” credentials
- Unfold the “Mein Passwort” section
- Copy the field called POP-Id, it should start with “pop” and end with some random numbers
Windows
- Open cmd.exe
- type
ssh pop_id@titan07.inf.uni-konstanz.de - Use you university password to login, acknowledge the warnings you encounter (we can talk about what they mean after the workshop)
Mac OsX
- Open terminal application
- type
ssh pop_id@titan07.inf.uni-konstanz.de - Use you university password to login, acknowledge the warnings you encounter (we can talk about what they mean after the workshop)
Why use a shell?
- Everything is a file!
- Shell precisely/automatically modifies files
- Basic shell and filesystem knowledge needed for git
Unikn: Being able to use shell and git is essential for “Programmierkurs 1” and “Schlüsselkompetenzen der Informatik”.
Filesystem Structure
- Tree
/root and delimiter between directories/files.shorthand for current directory..shorthand for parent directory./../../file.txtrelative path/home/user/homework.texabsolute path.sshhidden file
CAVEAT: Not the layout of bits on a drive.
Remark: Everything is a file — even a keyboard or microphone.
How do I interact with the filesystem?
lslist files in directorypwdprint working directorycd PATHchange directory to PATHmkdir PATHcreate directory at PATHmv SOURCE DESTmove SOURCE to DESTINATIONcp SOURCE DESTcopy SOURCE to DESTINATIONtouch FILEcreate empty FILEnano FILEedit file
General structure: command -flags -- path
How are ownership and permissions managed?
$ ls -laWhat is this string in front of the actual filename?
drwx:rwx:rwx
User:Group:All Permissions to (r)ead, (w)rite and e(x)ecute files.User and group are also listed.
CAVEAT: Directories should always be executable.
How do I interact with permissions?
chmodchange the rwx bitschownchange ownership of a file
CAVEAT: root can access everything / information is physically on disk.
How do I find the precise options for chmod and chown?
- man [chmod|chown]
- Generalization:
man word(sometimes number before word, seeman man) - Programs might have —help/-h options, sometimes
info program - Search engine or LLM
Spoiler: [chmod|chown] is a regular expression.
Why should I use git for version control?
- Versions of text
- Collaboration on text
/<-o
o<-o<-o<-o \<-o<-o<-o<-o
\<-o<-o/- o
- commit
- <
- reference to previous commit
How should I use git?
How do I create my first repository?
$ git init foo # initialize foo as a git repository
$ cd foo # move to foo
$ git config user.name "Foo BarBaz" # tell git your name
$ git config user.email foo@barbaz.com # tell git your email
$ nano README.md # start a project with a good README
$ git add README.md # tell git to care about the file
$ # you will need git stage before later commits
$ git commit -m "Add README" # Make your first commitCAVEAT: Older git versions create a default branch called
masterinstead of the more modernmainon startup, but usually display a warning, when they do so. You can just carefully follow those instructions to renamemastertomainso that you don’t get cryptic errors when you try to push to a remote that is initialized tomain.
- $
- user prompt,
- #
- root prompt/comment
What if my friend has already created a repository and published it on the web?
$ git clone URLHow would I publish my work?
$ git remote add origin URL # tell git the url for the remote named origin
$ git push origin main # tell git to push the current branch to origin/main
$ git pull origin main # tell git to pull the changes from origin/mainUnikn: You can create your own git remote on theuniversity gitlab. To avoid confusion, explicitely uncheck the “Initialize repository with README” box when creating a repository in the web interface.
Unikn Remark: If you are part of non-personal namespaces, take care to select the correct one for your repository.
I forgot where I left off, how do I orient myself?
$ git status
$ git logHow do I commit with style?
Imperative mood sentence, reference issue number if relevant
THIS LINE IS BLANK
- bulleted list of relevant information
- https://maybe.a.linkWhat should I commit?
- JUST code & raw documentation
- No binaries (a few images for a website are fine)
Remark: In the rare case of having to check in binaries, use git lfs.
I heard scary stories about conflicts?!
- Push and pull to avoid, freshman debugging algorithm otherwise
CAVEAT: How do I stop myself from accidentally committing things?
- Create
.gitignoreand enter the files
- Use the freshman debugging algorithm for details
The Freshman Debugging Algorithm
- Read carefully! (your problem, the command you tried, the result you got)
- Collect more information!
- ls, pwd, —help, man
- git status/log
- lecture slides
- next exercise on the sheet
- Can you combine concepts?
- Query a search engine or LLM with the error code or problem description.
CAVEAT: plagiarism!
- Ask via Discord/PZ809
- Love it at least a little!