git and the command line
- Juancho Capic
- Eric Schrijver
- wendy
- OSP
- Magda Tyzlik-Carver
- Christoph Haag
- Peter Reid
- S V
- Loraine Furter
- Anne Laforet
- Gijs Heij
Command-line
- Another way to interact with your computer.
- Use text commands to instruct your computer.
To open a terminal: Accessoires/Terminal.
Basic terminal commands
The first thing written in the terminal is the path, indicating where you are with the terminal, and the way to get there through the enclosing folders. The ~ sign represents your home directory, it is equivalent to the path “/home/user”.
- NameOfComputer:~ user$
In tutorials in general, we use $ to say “after that $ type something”. For instance $ cd means “type cd”. Here, we decided to remove the $ sign so we can just copy paste directly into the terminal.
- pwd
- mkdir relearn
- cd folder
- cd ..
- cd nameofafolder/nameofafolderintheotherfolder
- cd
- man nameoftheprogram
- sh
- #
- mv
- mv file1.jpg file1_new.jpg
- cp file1.jpg file1_new.jpg
And in general:
- [nameofthesoftware] nameofthefile
- ls
- touch nameofthefile.txt
Various tips
- The terminal commands basically call programs. cd is a little program. But you can call larger programs like mpost (MetaPost) too. Which commands you have available thus depends on which software you have installed.
- The parts you put after the name of the command, are called the arguments. Arguments are often the names of files: mpost drawG.mp will call MetaPost to convert the file drawG.mp.
- You can use switches to supply a program with further options. They are like arguments, except that you specify them with a dash, e.g. ls -lh
- lists files in the current directory in a Long and Human readable format
- Use the tab key to autocomplete names of programs or files.
- To have spaces in filenames you have to put quotes around the filename: “example 1.jpg” or escape the space in the filename: example\ 1.jpg. “Escape” means excluding the following character from bash interpretation and is done with the backslash \ character.
- Use the up arrow ↑ to access a memory of previous commands, and the down arrow ↓ if you went to much into the past.
- && means: do two actions with two programs one after the other, but only if the first one is successful:
- mpost drawG.mp && evince drawG.1
Further reading
Practice:
- Zed Shaw: The Command Line Crash Course
- http://cli.learncodethehardway.org/book/
- I like tight pants and mathematics and absolute beginners: unix for art students
- http://i.liketightpants.net/and/absolute-beginners-unix-for-art-students-part-1
- http://i.liketightpants.net/and/absolute-beginners-unix-for-art-students-part-2
- http://i.liketightpants.net/and/absolute-beginners-unix-for-art-students-part-3
Theory:
- Florian Cramer, “(echo echo) echo (echo): Command Line Poetics”, http://reader.lgru.net/texts/echo-echo-echo-echo-command-line-poetics/
- Thomas Scoville, “The Elements Of Style: UNIX As Literature”, http://theody.net/elements.html
- Neal Stephenson, In the Beginning was the Command Line, http://www.cryptonomicon.com/beginning.html
Note to selves: mistakes from the command line are almost always because of rushing too quickly and making spelling errors. Meditation is an answer, if not the only answer.
Git
Git is a version management system. It is a way to keep track of work that has been done, and allows a group of people to work collaboratively. One is able to see who has changed what. People push their documented changes to a shared repository and collaborators can synchronise.http://ospublish.constantvzw.org/images/var/albums/Relearn-2013/relearn_small_1049.jpg?m=1377805207
More about Git: http://relearn.be/r/notes::merging
Setup Git
You need to tell Git with what name you want to “sign” your commits.Open up a terminal window and type these commands line by line in the terminal:
- git config --global user.name "My name"
- git config --global user.email "your@email-address.com"
To have colours on your terminal (makes it more legible):- git config --global color.ui true
We also need a way to authorize our server that you can write to it.If you have the virtual machine that’s already done.
Otherwise, you need to generate an “ssh-key”.You can check if you already have one:
- cd ~/.ssh/
- ls
If there are files like id_rsa.pub you already have a key!If not, run :
- ssh-keygen -t rsa -C "your@email-address.com"
It will ask you where to put it, you can just type Enter for the default location.Then it asks you for a passphrase, meaning a password.
Then you display the key:
- cat ~/.ssh/id_rsa.pub
Copy it (Ctrl-Shift-C) and paste it on the pad, a bit below (ssh-keys).
Then, you’re ready to clone the Relearn repositories :Maybe first, create a Relearn directory on your computer.
It is already created on the virtual machine.
- mkdir ~/relearn
- cd relearn
So now you can clone the worksessions repositories:- git clone git@git.constantvzw.org:relearn.gesturing-paths.git
- git clone git@git.constantvzw.org:relearn.can-it-scale-to-the-universe.git
- git clone git@git.constantvzw.org:relearn.off-grid.git
- git clone git@git.constantvzw.org:relearn.Xtreme-Pattern-Methods.git
And if you want the repository of the website:- git clone git@git.constantvzw.org:relearn.be.git
And/or the one from the publication:- git clone git@git.constantvzw.org:relearn.publication.git
Exchanging files between the virtual machine and the host computer:http://www.ludi.be/erg-libre/index.php?n=PmWiki.VirtualBox
To clone a repository
- git clone git@git.constantvzw.org:[repository name]
Basic commands
- git status
- git pull
- git add
- git commit
- git push
- git status
- # "modified" [those that were modified]
- # "untracked files" [those that are new, not in the Git yet]
- # On branch master
- #
- # Initial commit
- #
- # Untracked files:
- # to include in what will be committed:
# git add ...
- git pull
git will try to ‘merge’ your changes with the changes made by others.
sometimes you need to resolve the conflict yourself
- git add filename
it adds it in the files “to be committed”
- git reset HEAD filename
- git commit
it opens nano, a text editor, to add a commit message describing your change
so you must add a description to the changes you are committing
try and type text at the top of the editor
the first line is the title/summary of the change
add a blank line
then expand if you want!
see the commands at the bottom: ^X to quit the editor, Y to say Yes: save
DONE!!!
- git log
it shows it in a shell, the sign : means there are several pages, and you can scroll with the arrows]
to close the screen type q
- git push
if others have also pushed in the meantime, you might need to pull first.
Order of git
- git add → git commit → git pull → git push
View Git diffs in another programme
(get the id of the file you want to look at through git log) → I used Meld- git difftool 12bc7aeead4e68abb206acb6803fa0205e2e9c93 petersfile.sh
- opendiff
- kdiff3
- tkdiff
- xxdiff
- meld
- kompare
- gvimdiff
- diffuse
- ecmerge
- p4merge
- araxis
- bc3
- emerge
- vimdiff
To create a new git repository
You need a space on a server to host your project. You can host it on your own server, on Gitorious http://gitorious.org/ or on GitHub https://github.com/. Gitorious is a free software Git hosting service, GitHub is a similar service which is closed-source but more popular. For those two online services, you need to create an account, and then there are simple explanations to create a new repository.Then, you can copy/paste the address to clone your project on http://relearn.be/w/relearn::repositories so that we have a shared place to share different projects. Put a one line description to invite people to look at your project.
http://git.constantvzw.org/?p=relearn.cheat-sheet.git;a=blob_plain;f=git-scheme.svg