2024-10-02
The end goal is to understand how to use git & Github. This means building our castle of Github-knowledge, but we don’t want to build it in the air. Rather we build up the foundations layer by layer:
The idea is to build from the ground up. This means that questions like “why it it like this”, or “what is that based on” are very much allowed and encouraged.
I don’t know what you don’t know, so please stop me if I assume that something is known!
Layers
bashgit) exposes to the shell (command line) that controls what the program does.git-bash) provide hundreds of small command line programs.Simply speaking, each CLI program gets a list of parameters (command line parameters). These are like function parameters. Some change on which file(s) the program works (e.g. ls file1.txt file2.txt), some change the output (ls -l), some tell the command what to do (git commit)
Parameters are separated by space. If you want a parameter with a space inside the parameter (e.g. a filename with a space), you put it between quotes, or use backslash:
In most unix command-line tools the following conventions are used (however there are exceptions):
ls -l).
ls -l)grep --help)grep --help == grep -h)ls -l -a == ls -la)ls -la is ls with two flags. ls --la is ls with a single long flag.git --worktree=/Users/reinoud/test == git --worktree /Users/reinoud/testIn the whole world backslash (\) is an escape character, and forward slash (/) is a directory separator:
double_quote <- "\"This is a quote\""
single_quote <- 'It\'s a sunny day'
path <- "C:\\Users\\YourName\\Documents"However historically in Microsoft shells (DOS (cmd.exe), PowerShell, not git-bash):
^) sometimes escapes spaces (*sigh*)mkdir -v -m 0777 project1 project2
||||| || || |||| |||||||| ^^^^^^^-- positional argument 2
||||| || || |||| ^^^^^^^-- positional argument 1
||||| || ^^ ^^^^----- flag with argument
||||| ^^-- flag without argument (verbose)
^^^^^--- program namegitgit is a command-line program that runs on your computer, allowing to do version control. It can send your changes to other computers and retrieve them from other computers (push and pull), but can certainly work 100% locally as well. git is free and open source.
Site: https://git-scm.com/ (git source code management)
Github is a website (launched 2008, owned by Microsoft since 2018). It allows git to push and pull to a central location. In addition, it offers other tools for cooperation (bug tracking, project planning, etc). Basic use of Github is free, however there is controversy that code on Github is being used to train AI.
There are alternatives to Github, GitLab and BitBucket being the most used.
Site: https://github.com/
git ≠ Githubgit started as a terminal program.
These days there are lots of GUI alternatives, but to really understand how git works, you need to understand it’s command line interface.
Also, the command line is the most wide-spread version of git and has the most descriptions on how to do things online.
MacOS:
Terminal.appgit version: brew install gitgit version: git --versionWindows:
bash) + git: https://gitforwindows.org/Personally, I do most of my things in terminal (including coding / making this presentation / etc) but this is excessive
Not well suited for graphical applications (photo/video editing / web browsing (usually) / etc)
⚠️You can break things very much⚠️
rm -r mydir/ vs rm -r mydir /
⚠️Generally be weary when copy-pasting things into your terminal⚠️ (or typing things other people tell you to type)
On the other hand, if you’re careful, things will be ok
Works in the same environment as GUI (files and directories)
shell is always “in” some directory (called working directory). Commands are usually relative to working directory, so it’s important to know where you are
Most (basic) commands are supposed to run non-interactive (this is because that way they could be used in scripts)
pwd, ls -la, cd .., cd #dirname#.A unix shell is a fully fledged programming language, and we could fill a 10 week course with just the shell basics. Instead, we will introduce new concepts as we get to them.
pwd: print working directoryls: list directorycd: change directory (e.g. cd project)mkdir: make directory (e.g. mkdir project or mkdir -p project/Armdir: remove empty directory (e.g. rmdir project)touch: creates an empty file (e.g. touch README.md)cat: print out a file (e.g. cat README.md)cp: copy a file (e.g. cp README.md README2.md or cp README.md project)mv: move (rename) a file (e.g. mv README.md README2.md or mv README.md project)rm: remove (delete) a file (e.g. rm README.md)nano: simple text editor (may or may not be installed)history: shows previous commandsexit: quit this shellecho: print (e.g. echo "hello gdansk")Redirects:
>: redirect stdout to file (overwrite; e.g. echo hello > test.txt)>>: append stdout to file (e.g. echo hello again >> test.txt)|: send stdout as stdin of next commandSeparators between commands on same line:
;: end of command&&: “and”; next command only runs if previous succeeded||: “or”; next command only runs if previous failed$(cmd) execute cmd and put the output in place of this. e.g echo "I'm in $(pwd)"~: home directory/: directory separator; if at start: absolute directory. if by itself: root/root: home directory for root user (note: NOT root directory)/home/NAME/ or ~NAME/: home directory for NAME user.: current (or same) directory..: one directory up/tmp: place for temporary files (e.g. removed after restart).xxxx: hidden file / directory (starts with .)*: 0 or more characters?: 1 character[abc], [a-z]: any of the characters in a, b and c or between a and z{mp4,MTS}: either mp4 or MTSNote: in *nix stuff generally is case-sensitive
general idea filename.ext; extension no special meaning in linux
-h / --help: (usually) shows some help about a command. (e.g. mkdir -h)
man: shows manual page (if available; e.g. man mkdir)
<TAB> is your friend