Command Line#

We will begin with an overview of the Command line (also command shell).

Review of the Command Line#

During this workshop, you’ll be communicating with GitHub from your local computer via the command line (the Terminal or the Git Bash on Windows). This section reviews some of the basic commands that will also be used in this workshop.

In addition to the command line, you’ll be using your text editor and your browser. Before continuing, its important that we clearly distinguish between these three different spaces or environments:

  • Your plain text editor where you’ll be writing your document is on your local computer.

  • That document is initially saved in a git-enabled repository on your local computer.

  • Your browser is where you’ll be uploading your repository to GitHub, a cloud service.

  • Your terminal is where you’ll be communicating with GitHub to send the repository and project files back and forth between the cloud (which you can view through the GitHub website) and your hard drive.

Because you’ll be moving between these three spaces throughout the workshop, you may want to use (command (⌘) + tab) or (control + tab) to move quickly between the three windows on your desktop.

Accessing the Terminal#

macOS#

Hold the command (⌘) key and press the space bar at the same time to bring up the “Spotlight Search” window. Type terminal, followed by enter to quickly open the Terminal.

Windows#

Press the windows button on your keyboard. When the search menu pops up, type git bash and press enter.

Practice Navigating the Command Line#

If you don’t feel comfortable navigating your hard drive through the command line, here is a short section catching you up.

  • If you feel fairly comfortable using the command line, you can skip this .

  • If you do not have experience or prior knowledge of the command line, you may want to work through one of the following workshops: Introduction to the Command Line or The Unix Shell

You can create the folder anywhere on your hard drive by typing the following into your terminal and hitting enter.

$ cd <directory-name>

Let’s practice this command by using it to take us to our Desktop. Type the following command into your terminal and hit enter.

$ cd Desktop

This will change your current working directory from /Users/<your-name> to /Users/<your-name>/Desktop.

Note for staff or company computers#

If your computer has multiple users you can choose your user profile in the C: drive or you type the following command in your terminal and and hit enter

$ cd C:/Users/[put your username such as SMU ID here]/Desktop/

Check your current directory by typing the following command into your terminal and hit enter:

$ pwd

Now, use the following command to go up one directory:

$ cd ..

Check your current directory again using the following command. You should be back in your “home” directory:

$ pwd

Practice going back and forth between your Desktop and your home directory.

When finished, go to your Desktop folder and check that you’re there with pwd.

Making a Projects Folder#

In this session, we will be making a syllabus and using Git to keep track of our revisions. Let’s create a Git project folder.

If you don’t have a projects folder on your desktop, create one using the following command:

$ mkdir projects

From Desktop, Navigate into your projects folder using the following command:

$ cd projects

Then create a git-practice folder with the following command:

$ mkdir git-practice

Navigate into the new git-practice folder using the following command:

$ cd git-practice

At this point, when you type pwd, your folder structure should look like this:

$ pwd
/home/<username>/Desktop/projects/git-practice

TO see what files are in a folder, ls, it will show what files are there. To see all files, including invisible, type ls -a

$ ls

$ ls -a

Authenticating to Remote Git Repositories
“Git provides multiple protocols for authenticating to and interacting with remote Git repositories.

There are three main approaches you can take:

Evaluation#

Which command do you use to make a new folder?

  • pwd

  • cd

  • mkdir*

Which command do you use to enter into a folder?

  • pwd

  • cd*

  • mkdir

Which command do you use to check where you are?

  • pwd*

  • cd

  • mkdir

Shell Cheat Sheets#

Summary of Basic Commands

Action

Files

Folders

Inspect

ls

ls

View content

cat

ls

Navigate to

cd

Move

mv

mv

Copy

cp

cp -r

Create

nano

mkdir

Delete

rm

rmdir, rm -r

Glossary#

Pro-tip for the Command Line: How to exit unknown screens#

If you’re ever stuck or “trapped” on the command line, try running through these common exit commands to return to the prompt:

  • control + c

  • control + d

  • q followed by enter

  • :q followed by enter

control + c attempts to abort the current task and restore user control. control + d escapes the current shell environment—if you use it at the normal $ prompt, it will end the current command line session. q is often used as a command (followed by enter) to escape from specific programs like less. :q is the command used in vi that changes the mode of interaction (:), allowing you to enter the q, a one-letter command to quit, which must be followed by enter. Thus, it’s a command specific to vi.

Evaluation#

Which best describes where you are working when you’re writing in your plain text editor:

  • on my local machine*

  • on the internet

Which best describes where you are working when you’re using your terminal to communicate with GitHub and share the files:

  • on my local machine*

  • on the internet

Which best describes where your files are when you are viewing them in GitHub:

  • on my local machine

  • on the internet*

Git-enabled repository means

  • none of the files on my local machine are being tracked

  • a specific file on my local machine is being tracked

  • a specific folder on my local machine is being tracked*

  • all the files on my local machine are being tracked

Which command do you use to make a new folder?

  • pwd

  • cd

  • mkdir*

Which command do you use to enter into a folder?

  • pwd

  • cd*

  • mkdir

Which command do you use to check where you are?

  • pwd*

  • cd

  • mkdir


Shell Cheat Sheets#

Summary of Basic Commands

Action

Files

Folders

Inspect

ls

ls

View content

cat

ls

Navigate to

cd

Move

mv

mv

Copy

cp

cp -r

Create

nano

mkdir

Delete

rm

rmdir, rm -r

Glossary#