Check if Git is Installed
First check if Git is installed on your machine. Mac instructions here:
$ git --version
$ git version 2.14.3 (apple Git-68)
Personalize Your Git Settings
Set you name and email. It will seem like nothing happens. This is OK.
$ git config --global user.name "YourName"
$ git config --global user.email "email@example.com
Create A New Folder
Make a folder on your desktop. Call it something like sites or devel. Change directory to the folder you just created
$ cd /your/working/directory/sites
Make A Directory
Make a directory within sites or devel. The $ sign denotes your working directory. If you are not sure what your working directory is type PWD
$ mkdir "new_folder"
Change To That Directory
Type CD then drag the folder that you just created with mkdir to the terminal window. This will paste the directory of the new folder into you terminal.
$ cd /path/to/new/folder/you/just/made
Initiate Your Directory
You will need to initiate the directory. This means you are telling git to add a couple of hidden folders that keep track of the changes you make to the files in the directory.
$ git init
Create A File That You Will Edit
You can create an empty .html file from the command line with the touch command.
$ touch "index.html"
Check Git Status
Now that you have created a file. Git will start to track it. You can type git status to see the files that git is tracking.
$ git status
Add to Staging Area
First you need to add the file to the staging area before you can commit the file.
$ git add index.html
Check Git Status Again
Check git status again to see if the index.html file is in the staging area.
$ git status
The command line should output something like this:
No commits yet Changes to be committed: (use "git rm --cached
..." to unstage) new file: index.htmll
Once You Are Ready. Commit Changes
When you are happy with you changes and they are tested. You can commit the changes. Use git commit -m ‘Your note about changes’
$ git commit -m 'My First Commit'
Now Lets Say You Delete Some Files
Go ahead and write garbage into your index.html file. Then sure, why not, delete that file entirely. Check around. Yep, it’s gone. But, wait! Git to the rescue. Use the git checkout — . to get your files back to the way they were when you made your commit.
$ git checkout -- .
Look at that. They are back.
How to Work With GitHub
This lesson shows how to work with GitHub on your local machine. If you want to work with GitHub repositories Check out this guide, Working With GitHub.