One thing that makes learning Git hard for many students is that it’s a command-line program. If you’re not familiar with the command-line, this can be confusing.
A command-line is just an interface to your computer, totally analogous to the Finder or Windows Explorer, except that it’s text-based. As the name implies, you interact with it through “commands” — each line of input begins with a command and might have zero or more arguments, separated by spaces. The command-line keeps track of what directory (folder) you’re in, which is important to many of the commands you might be running.
On UNIX-like operating systems (OS X or Linux) open the Terminal application to use these commands.
On Windows you should install Git for Windows from the Git site. Then run the program Git Bash to open a terminal where you can run all these commands, in addition to Git commands.
Here are some of the most common commands:
cd
(stands for “change directory”)
Changes the current directory. In you’re in a directory that has a subdirectory called hello
, then cd hello
moves into that subdirectory.
Use cd ..
to move to the parent directory of your current directory.
pwd
(“print working directory”)
Prints out the current directory, if you’re not sure where you are.
On a well-configured system, your current directory is displayed as part of the prompt that the system shows when it’s ready to receive a command. If that’s not the case on your system, post on Piazza to get help configuring your prompt.
ls
(“list”)
Lists the files in the current directory.
Use ls -l
for extra information (a “long” listing) about the files. Use ls -a
(stands for “all”) to show hidden files, which are files and subdirectories whose names begin with a period.
mkdir
(“make directory”)
Creates a new directory in the current directory. To create a directory called goodbye
, use mkdir goodbye
.
up and down arrow
Use up arrow to put the command you just ran back on the command line. You can now edit that command to fix a typo, or just press enter to run it again.
Use the up and down arrow keys to navigate through your history of commands, so you never have to re-type a long command line.
This document is based on the 6.005 Getting Started Notes.