Terminal/Git Tutorial
Table of Contents
- Intro
- Terminal (Linux/MacOS)
- Terminal (Windows)
- Video
- Notes
- Introduction
- How to open a terminal
- Why to use a terminal
- Change directory of the terminal
- Terminal is in a specific directory (dir/pwd)
- Check the files and directories inside a directory
- Creating a directory
- Special directories "." and ".."
- Change directory from "C:" to "D:"
- Creating a file with echo
- Clear the powershell
- Git Introduction
- Git Working Example (Terminal)
- Video
- Notes
- Introduction
- Github Account
- Creating a repository
- Cloning the repository onto your computer
- Username and Password
- Repository is now on your machine
- First steps with git [Exercise]
- Committing a file to github
- Adding changes to one commit
- Check the current state of our repository
- Create a commit (Savestate) from all the added changes
- Send the commit to github
- Error during Push and being a collaborator
- Push is now possible
- Check the latest commits
- Typical workflow with git
- Restoring a file
- Exercise
- Git Working Example (App)
- Cheatsheets
Intro
Video
Notes
Tutorial Introduction
In this Video I explain how to use this website and what the content is.
The Headline will pop open when I say it will
See!!! it is working
Click here to hear me say "Oh hello there!"
Terminal (Linux/MacOS)
Video
Notes
Introduction
This Video explains how to use the Terminal on Linux and Mac.
Windows User please click on the Terminal (Windows) tab above
Mac Terminal vs Linux Terminal
Terminal on Linux and on Mac are mostly identical.
The look is a little bit different but it works the same.
Additionally I don't have a mac machine so I can only present it on Linux
Enable the Terminal app on your machine
To enable the Terminal on mac please see the following URL:
https://www.howtogeek.com/682770/how-to-open-the-terminal-on-a-mac/
What is the terminal
- Allows to work much faster (after some practice)
- Easiest way to use git
- It is same for all systems
- It is same for all systems
Command: pwd
The Command pwd prints the current working directory,
or with other words: "Where you currently are with your terminal".
pwd
Command: ls
With the command ls you get a list of all files and directories in
the current working directory.
ls
Command: cd
To change the directory you are currently in, you need the change
directory the command is cd.
cd <directory you want to change to>
Autocomplete the directory with pressing [TAB]-Key after some letters
cd TL_[TAB]
Command: mkdir
Creating a directory can be done with the mkdir command and the name
of the new directory.
mkdir newDirectory
For directories with spaces you need to double quote the name
mkdir "My awesome Directory"
Special directories "." and ".."
Every directory has two special directories inside of it. The "." is
the folder itself.
cd .
The ".." directory is one folder above
cd ..
Creating a file with "touch"
The command touch allows you to create a new file.
touch myAwesomeFile
For file with spaces you need to double quote the name
touch "my Awesome File"
Clear your terminal
The command clear will clear you terminal and make it look nice.
clear
Some Additional "tricks"
Move multiple directories with one command
cd dir1/dir2/dir3 cd ../../
Look what is inside a directory without visiting it
ls dir1/
Terminal (Windows)
Video
Notes
Introduction
This Video explains how to use the Terminal on Windows.
Mac User please click on the Terminal (Linux/Mac) tab above
How to open a terminal
There are two possibilities: "Windows Powershell" (blue) and "Command
Prompt" (black).
Just search for the name in the start menu.
Why to use a terminal
- Allows to work much faster (after some practice)
- Easiest way to use git
- It is same for all systems
- It is same for all systems
Change directory of the terminal
A Terminal is always inside of a specific directory.
To change the directory you can use the cd command.
Powershell:
cd <name of directory>
Command Prompt:
cd <name of directory>
Autocomplete the directory with pressing [TAB]-Key after some letters
cd Des[TAB]
Terminal is in a specific directory (dir/pwd)
A Terminal is always inside of a specific directory.
You can see the directory printed in the terminal before your cursor.
But you can use commands to be check the directory:
Powershell:
pwd
Command Prompt:
dir
Check the files and directories inside a directory
To see the directories and the files inside the current directory use
the following commands:
Powershell:
dir ls
Command Prompt:
dir
Creating a directory
Creating a directory with the terminal is done by the md command
Powershell:
md nameOfDirectory
Command Prompt:
md nameOfDirectory
Directories that should have a space need to be quoted:
md "My awesome Directory"
Special directories "." and ".."
Every directory has two special directories inside of it. The "." is
the folder itself.
cd .
The ".." directory is one folder above
cd ..
Change directory from "C:" to "D:"
Every device on windows that is connected gets a letter. "C:" is the
letter for the device where windows is installed. Your USB-Stick can
be maybe under "D:" or some other letter.
To change into the devices, you don't use cd but just write the
specific letter.
For Example:
D:
Creating a file with echo
To create an empty file in my current directory we can use the echo command:
echo > <name of file>
To already add some text inside the file (not very useful for the
beginning):
echo "some text" > <name of file>
Similar to directories, files with spaces need to be quoted:
echo > "my awesome file.py"
Clear the powershell
To clear the current text inside the powershell use the clear
command. This does not work for the command prompt…
Powershell:
clear
Git Introduction
Video
Notes
Introduction
If you don't have git installed please install it with following help:
https://github.com/git-guides/install-git
Mac Users:
You probably have git already installed, please see the instruction in
the above link.
Windows user set following settings:
Agenda
Savestates
Git according to Wikipedia
Differences Git and Github
Git Working Example (Terminal)
Video
Notes
Introduction
Some word that represent an intro to this clip.
Github Account
To use github you need to have an account.
The process is in most parts self explanatory.
I use two different accounts to represent the collaboration between
two people.
- Right: TechLabs account [Repo Creator]
- Left: Personal account [Collaborator]
Creating a repository
You/Someone needs to create a repository on github.
- Press the "new" button
- Give it a name
- (Optional) write a description
- Set the visibility [public is fine!]
- Add a README for good practice
Cloning the repository onto your computer
To be able to work with the repository you need to clone it onto your
computer.
You do this by getting the url to the repository by clicking on the
"Code" button and copy the url.
Open up a terminal and change directory to where you want to have the
repository on your computer.
Clone the repository with the git clone command:
git clone <url>
Username and Password
At this point the terminal will ask you to enter your Username and
Password. Just enter the Username and Password that you used while
creating the github account.
Repository is now on your machine
The repository is now as a directory available on your machine.
The folder on your machine and the repository on github are now
connected.
For technically interested:
There is a hidden folder called ".git" where all needed information
are stored. (There is no reason to look inside/change something inside
this folder)
First steps with git [Exercise]
We will create a new file with our name as filename and a nice short
message inside of it.
Committing a file to github
There are three steps to do to get the changes into github:
Adding changes to one commit
We need to "add" all files that we changed.
git add <name of file>
To add all changes:
git add .
[Here you see the special directory ".". This means add all changes
/in this directory/]
Check the current state of our repository
We can check what changes are currently done on our repository by
using:
git status
Create a commit (Savestate) from all the added changes
All added changed can now be stored as a commit.
Every commit needs a message so we need to use the -m flag and type
a message inside quotes.
git commit -m "a nice message"
Send the commit to github
The commit is only created locally on your machine. It is not on
github and so not available for anyone on your team.
To send the commit to the server we need to push it:
git push
[During git push you will be asked for your username and password]
Error during Push and being a collaborator
When you are not a collaborator to the project you will get an error.
The repository creator needs to send you an invite:
- Settings
- Manage Access
- Invite a collaborator
- Search for the username
Now the user needs to accept the invite. The invite can be found by
the bell icon on the upper right corner.
Push is now possible
With the access granted by the collaborator it is now possible to use
push your changes to the repository.
Check the latest commits
To see the latest commit you can use the clock icon inside github.
Typical workflow with git
First time and only once:
Get the repository onto your machine:
git clone
Every time before starting to do some changes:
Updated changes from the remote repository to you:
git pull
- Change something inside the project
Add the changes:
git add changedFille
git add .
Create a commit
git commit -m "describe your changes"Send the commit to the server
git push
Restoring a file
Should you want to go back to the state the file had in the last
commit you can do this with a restore command:
git restore <name of file>
Exercise
You should test this steps at least once.
For this I have a small exercise:
- Create your github Account
- Send me via Slack your username
- I will inform you when I made you a collaborator
- Commit/Push a file with your name as filename with a small nice
message inside into this repository:
https://github.com/marco-techlabsHH/tl_git_ex_ss21 - At the end of the file write if you used the Terminal or the gui
app
Git Working Example (App)
Video
Notes
Introduction
Watch the Terminal Example
This video references the example from the git via terminal
video. Watch it at least once before watching this.
Where does this video starts
- Repo is created
- I am a collaborator and added something to the repo
- Installed the app
- Logged in the Github App