-
-
Notifications
You must be signed in to change notification settings - Fork 5
Lecture 1.2: Command Line, Git
The Command Line Interface (CLI) lets you interact with your machine using text commands. Such a method of interfacing is very powerful specifically for performing more elaborate file exchanges and system configurations that are usually abstracted by a Graphical User Interface (GUI).
The main application where you type your commands is called a shell. Every machine or system uses different types of shells. The most common one is bash which is what Linux and Mac systems use.
On Macs, the bash shell application included as part of the system is called Terminal. You can typically find it in /Users/ComputerName/Applications/Utilities/ or just by searching for Terminal in Spotlight.
Windows systems include a lighter version of a bash shell called Command Prompt but it is very limited compared to the common bash shell. For Windows users, we will need to use a third-party application called Cmder that replicates the possibilities of a bash shell.
In the video lecture, we will show some examples of what can be done in the Terminal.
Description | Command |
---|---|
Execute command with admin privileges | sudo <command> |
Find out which directory you're in (present working directory) |
pwd |
Go home | cd ~ |
List the contents of the current directory | ls |
List contents with hidden files & permissions | ls -la |
Change to a directory | cd /path/to/caligrafy |
Go back one directory | cd .. |
Make a directory in current directory | mkdir caligrafy |
Remove a file (with confirmation) | rm foobar.txt |
Remove a directory | rm -R foobar/ |
Create a new file | touch caligrafy.php |
Re-enter previous commands | Up arrow |
Abort | try ctrl + z or ctrl + c
|
Git is an application that provides Version Control. In order to understand what git is, we need to understand what Version Control is first.
Version Control has long existed since the beginning of tracking changes on written manuscripts. In the digital era, that means keeping track of the different versions or revisions of a file by logging what the changes are, who made those changes and when these changes took place. This process became more and more important in the world of code development because large groups of people can be involved in making changes to the code, in some cases to the same code. Version Control is about keeping a record of all these changes, identify conflicts when they occur with the purpose of always keeping a single source of truth.
Git is one of the most recognized implementations of Version Control. There are others but it has become an industry standard that is widely used.
In this course, we will be using git for several purposes:
- Since it is an industry standard, it has become basic knowledge for anyone stepping into the development field
- In this course, we are going to build applications locally, on your own local machines mainly. However, we will create a backup of your code on the web (using a service called Github) so that you always keep the latest stable version of your code backed up. Through git you will be able to keep both versions of your code up-to-date by pushing your changes to the backup repository and inversely getting the code back from the backup repository to your local machine when you need it.
- In this course, we will show examples on how to create a production server. That is where your application will be published to be visible by the world. The production server is nothing more but another machine - just like your local machine and depending on what system is running on it (Linux, Windows etc.), it operates exactly like your local machine and it will help serve your PHP/HTML/CSS/MySql files so that anyone can see the result from their browsers. Git will also help transmitting the latest and greatest version of the code from your local machine to the production machine in a quick and efficient way.
Downloading git on Mac systems is straightforward:
- Open the Terminal
- type
git --version
- If git is already installed, you will see an output similar to this (versions might vary):
git version 2.15.2 (Apple Git-101.1)
- If git is not installed, you will be prompted to install it. Follow the instructions by accepting the
xcode
command downloads. Once done, repeat step #2 above and you should be able to see the same output as step #3 if the installation was successful.
You can download the git through the installer directly from the git website. This will give you the latest version. This method works for both Mac and Windows. Download git.
Open the package and follow the instructions. Once the installation is completed:
- Open Cmder (Windows) or Terminal (Mac)
- type
git --version
- If the installation was successful, you should see an output similar to this (versions might vary):
git version 2.15.2 [..]
Once you complete the git installation, we need to do some initial setup on git. This is a one time kind of setup and it can be done in the same way for both Windows and Mac systems.
- Set up your user information. This informations is just to identify you on any changes and transactions that you make locally. Type the following commands:
$ git config --global user.name "Sam Seaborn"
$ git config --global user.email sam@gmail.com
- Color code the output of git, this will help make things more readable by typing the following:
$ git config --global color.ui true
- Make sure that git ignores any permission changes that you do locally on your machine. You probably don't want to apply these permissions when you are backing up your code or even more when you are transferring the code to the production server. Type the following:
$ git config --global core.filemode false
- Configure how git handles line endings. This is necessary based on the git documentation to ensure that cross-compatibility across different systems.
- For Mac, type:
$ git config --global core.autocrlf input
- For Windows, type:
$ git config --global core.autocrlf true