Terminal — bash — Git Basics

> Making a basic Git Repository

In your terminal, navigate to the directory you want to track.
For now, create an empty directory (or “folder”) with the mkdir command:
mkdir my-new-git-repo

Once you’ve made your directory, move into it via command line with the cd command:
cd my-new-git-repo

If you want to make sure it worked, you can enter pwd. It should return the path to your new directory ( /Users/[yourname]/my-new-git-repo ).

Initialize git in your directory by entering:
git init

You should see something like “Initialized empty Git repository in /Users/[yourname]/my-new-git-repo/.git/”

Make a new file to track with git. Use cat to create a text file called hello.txt: cat > hello.txt

The terminal should bring you to an empty line. Type in Hello, world! (or whatever you'd like to save in a text file) and then press Ctrl + D to save.
If you enter cat hello.txt (no > this time), your terminal will show you the contents of your text file. You should see the text you just typed.

Let's check on git now. You can do this by entering:
git status

You should see a message that includes this:

Untracked files:
  (use “git add” ...” to include in what will be committed)
  hello.txt

Let’s do exactly that. Add your new file to be tracked by Git:
git add hello.txt

If you enter git status now, you’ll get a similar message, but hello.txt will be in green and under the heading “Changes to be committed:”

A commit is a message Git will store that describes the changes you’re making and asking Git to track. It can be as detailed or basic as you want.

To commit your changes, use >git commit, add a -m, then enclose your message in quotes:
git commit -m "created hello.txt, a text file containing Hello, World!"

It’s also common for your first commit in a new repository to be “first commit,” like so:
git commit -m "first commit"

> Continue to Pushing to GitHub