Try Git | Markdown Cheatsheet | Pro Git | Git Config
Getting Started
In the terminal start by creating a new directory, then run git init
to initialize a git repository
mkdir my_new_directory
ck my_new_directory
git init
Now that we have initialized a git repo, we can add files, and make edits, while trackin changes along the way. We can also revert back to previous 'commits' and merge branches. We'll go into detail about these terms mean and do shortly.
For this example, let's create a static website with a couple of pages, stylesheets, javascripts, and maybe even some fonts.
Tracking Changes
Create a file called index from the command line, then check its git status.
touch index.html
git status
You should notice that index.html is in 'untracked files'. In order to add this file to be tracked, we can run git add index.html
. If you have changed several files and want to add them all, you can add all files with git add .
When we add files, we say they are staged or have been added to the staging area. Add the index to the staging area and check the status again.
git add index.html
git status
You should now see that index.html a change to be committed. So far, we have initialized a git repository, created a file, and added it to be staged. We can now 'commit' to make a saved point we can revert back to later, if we wish. When we create a git commit, we should give it a message (preferably a meaningful message).
git commit -m "Add index file for site homepage"
Now if we try git status
we can see there is nothing to commit. Try git log
to see a log of the commits in this repo. This is useful for git commands such as revert, reset, and checkout.
Build Out the Site
Open up index.html in your favorite editor (sublime, etc.), and fill in some valid HTML.
note: Open the file with Chrome from the command line, using open -a "google chrome" index.html