Git Basics

Getting Started with

git config

• Associate your name and email address with your work

git config --global "Your Name Comes Here"
git config --global


Intitialize Your Repository

• Make a directory to store your work and cd to that directory

# Initialize repository
git init

• You have created a local repo within your project contained in the hidden directory .git. This is where all of your change history is located on your local workstation


Checking Status of a Repo

# Check status
git status

• The command git status tells you the following:
◇ What branch are you on (see Branching)
◇ The last commit message
◇ Changes made in files since last commit
• You will see that the status of your repo will change once we add files and start making changes


Adding (Staging) Files / Directories

# git add: Add files/ dir from Working Directory --> Staging Area
# Add a file
git add <file>

# Add certain file types
git add *.html

# Add all files & directories
git add -A
# or
git add .


Exclude Files / Directories with


• To stop Git keeping track of changes in certain files / directories in your local repo, you can specify them in file “.gitignore” (hidden file)


Commit Your Changes

• In order to store your changes in your git repo, you need to commit them

# Commit
git commit -m "Put remark/message here"

• Git uses a SHA1 hash to file away your changes. You can see the short hash “7be53cc” in the output of git status command

git status

# Output
[master (root-commit) 7be53cc] Add inspirational quote
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt


Looking at Your Commit History

• To view the most recent commits, you use the command git log
• You can see the full hash “7be53cc330db1207c9b26fe560704f90405742fd
” in the output

# View log
git log

# Output
commit 7be53cc330db1207c9b26fe560704f90405742fd
Author: John Doe <>
Date:   Sun Dec 20 07:48:29 2015 -0700

    Add inspirational quote


Viewing the differences between two commits

• Use the git log command to find two commits to compare

# Difference between two commits
git diff 7be53cc d553bb