--- title: MDEF - GIT Class description: Trobuleshooting Autors: FLU --- ###### tags: `MDEF` `Git` ---- [TOC] :::info How many times have you done this? **report_final_real_final_actually_yes_final_final.doc** **report_edu_2019_10_15.doc** **report_edu_oscar_2019_10_15_12.36.doc** GIT: report.doc ::: ## Git cheatsheet ### Fast guide to upload and update your repo to the GITLAB <iframe src="https://docs.google.com/presentation/d/e/2PACX-1vTyN2MIrFMmpB8sOU7hZthSXD8BQDUC9p82eFvN49gNtRkWMzib6rLup3mU97mjnfNtSfLnrL1wHHiq/embed?start=false&loop=false&delayms=3000" frameborder="0" width="700" height="425" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe> #### GITLAB ACCOUNT 1. Got to [Gitlab](https://gitlab.org) 2. Register as a new user 3. Username > **First Name + . + Surname “adelkittisarvary”** 4. Email > **Iaac student's email "adelkitti.sarvary@students.iaac.net"** ![](https://i.imgur.com/YQUt0jG.png) #### SETUP GIT (to do only the first time) 1. Install Git > * GitBash for windows users [Gitbash](https://gitforwindows.org/) > * Open command line for MacOSX user(Git is usually preinstalled on Mac and Linux.) [command line](https://blog.teamtreehouse.com/introduction-to-the-mac-os-x-command-line) 2. Add your Git username and set your email > **git config –-global user.name “YOUR_USERNAME”** 3. Configure you email address for uploading > **git config -–global user.email “jSmith@mail.com”** 4. Check if you have an SSH KEY already > **cat ~/.ssh/id_rsa.pub** (If you see a long string starting with ssh-rsa, you can skip the ssh-keygen step) 5. Generate your SSH key > **ssh-keygen -t rsa -C "$your_email"** 6. Now let´s see your keygen > **cat ~/.ssh/id_rsa.pub** 7. Copy your key > Windows: **clip < ~/.ssh/id_rsa.pub** > Mac:**pbcopy < ~/.ssh/id_rsa.pub** > Linux **xclip -sel clip < ~/.ssh/id_rsa.pub** 8. Finally add the copied key to GIT on the web version <iframe width="560" height="315" src="https://www.youtube.com/embed/54mxyLo3Mqk" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> [Video on how to do it](https://www.youtube.com/watch?v=54mxyLo3Mqk) #### Sample image Sample![](https://i.imgur.com/tdCG4kj.jpg) #### COPY YOUR ACADEMY PERSONAL REPO. 1. Navigate to the folder where you want to put or create your repo. If you don´t know how to follow this [guide](https://www.digitalcitizen.life/command-prompt-how-use-basic-commands) * We recommend to create it in the desktop so you don´t have to dive into million of folders each time 2. Clone your student repository > **git clone git@gitlab.com:flu/mdef19-20-templateblogpage.git** #### UPLOAD YOUR REPO ONLINE. - Add the new files you added to git git add index.html to upload file by file git add . to upload all the files at once - To download the last copy from the repository git pull (for downloading the last copy of the repository) - To have a working copy of your repo git merge (to have a working copy) - Now name your update, so you know what you changed with this push. git commit -m ‘change you did’ - Upload to the Repository git push ## Introduction to the terminal ### Everything is a FILE [**Everything** is a file](https://en.wikipedia.org/wiki/Everything_is_a_file). Each file in your computer resides somewhere (in a directory), and each program in your computer is a file, hence, they live somewhere. You can know where they live, and make some programs yourself. But don't be afraid, the only thing you need is a file. Each program has an specific input and an specific output. These are know as std_in and std_out. For instance, a text editor can have a text input from your keyboard and an output to a file. > Every program on your computer has the ability to do a vast amount of different things. Read files, start other programs, do math, control devices. The main difference between bash and most other programs is that unlike them, bash was not programmed to perform a certain task. Bash was programmed to take commands from you, the user. To do so efficiently, a "language" was created which allows users to "speak" to the bash program and tell it what to do. This language is the bash shell language and you are about to become intimately familiar with it. > In essence, a shell program is one that provides users with an interface to interact with other programs. There is a large variety of shell programs, each with their own language. Some popular ones are the **C shell (csh), Z shell (zsh), Korn shell (ksh), Bourne shell, Debian's Almquist shell (dash), etc. Bash** (also called the Bourne Again shell) is currently the most popular and ubiquitously available shell. Even though all of these shells use seemingly similar syntax, it is important to be fully aware of what shell you're actually writing code for. Often, you'll hear people refer to their code as "shell code", which is about as specific as "source code" is when referring to your Java code. This guide will teach you how to write bash shell code: you should use it only with the bash shell, not any other. :::info Probably [the best guide](https://guide.bash.academy/) to learn what this all means. ::: **TL;DR** > Bash is a simple tool in a vast toolbox of programs that lets me interact with my system using a text-based interface. > ### Useful commands #### WINDOWS specific - **dir** - To view the contents of a directory, type "dir" - **del** - Subsequently, you might want to clean up useless files - **clip** - copy the output #### UNIX specific - **ls** - list files in a folder - **rm <filename>** - delete files. Be careful, it won't ask for confirmation and they won't be in the Trash!! - **pbcopy** - copy the output #### All - **cd <dir>** - It is frequently useful to know in which directory you are currently working To move between directories, use the cd command with the name of a directory example go to desktop is "cd Desktop" - **cd ..** go up a directory - **open <file>** open a file with the default - **mkdir <filename>** - To create a new directory - **pwd** - print name of current/working directory - **ls --help** - show help of ls command. - **ls -a** - list files in a folder (including hidden). - **ls -l** - show long listing format. - **man ls** - Format and display the on-line manual pages. - **mv [-f | -i | -n] [-v] source target** - **change name** or ~~move file~~ to specific folder - **cat <file>** - outputs file into std_output ### Redirection and pipelines We can redirect the std_out of a command to a specific target. Most commonly, this can be a file #### Basic redirection and appending - **echo "Hello" > file.txt**: Says hello, but redirects the output to a file (file.txt). Creates a new file - **echo "Hello" >> file.txt**: Says hello, but redirects the output to a file (file.txt). Appends it to the file #### Pipeline Pipelines are meant for command to command communication. - **pwd|pbcopy**: send the output of *pwd* command to the input of another command, in - **ps -ax|grep 'python'**: send the output of ps -ax (list of open processes) and only grab the ones that contain python in them ### Terminal specific features - **tab** - Executable search path. autocomplete the name during the process of type. - **double tab** - show all the options to autocomplete. ### In terminal applications **VI(M)** Screen-oriented text editor originally created for the Unix operating system. **Important:** - Edit a file: type **i** - > INSERT MODE - Exit INSERT MODE: press **Esc** - Quit. Out of any mode: type **:q** - Write and quit. . Out of any mode: type **:wq** - Dont' write and quit. Out of any mode: type **:q!** :::danger **Capital letters matter here** ::: * * * ## Troubleshooting * Run to the extended GIT CHEAT SHEET [TUTORIAL](git_cheat_sheet.md) * Official git [guide](http://www.git-scm.com/book) **Original tutorial by:** * [Eduardo Chamorro](http://eduardochamorro.github.io/beansreels/index.html), Fab Lab Barcelona 01.2019