Git Introduction

What is Git?

  • It's a version control system that track changes
  • We can work with Git and even know or care about Github at all

What is Github?

  • Github is not the same thing as Git. Git is a technology.
  • Github is a website/application that works with Git

Installing Git

Check if you have git installed in your environment git --version

Git Basics

Git init

Setup directory structure:

mkdir Git
mkdir Git/git_intro
touch app.js

Run git init in the directory where you want git to keep track with

  • Create a directory ".git" (hidden)
  • To see it, use ls -a
  • If you accidentally init git in the wrong directory, use rm -rf git to remove the .git folder

Git status

The command git status show status of followings:-

  • On branch master
  • Initial commit
  • Changes to be commit
  • Untracked files

File .gitignore

Git add

The command git add will add the file(s) that you want Git to track

// For single file
git add app.js

// For all files staged for commit
git add .

// For all files and directories
git add -A

Git commit

Must add before commit Rule of thumb: use present tense in message

// -m: message to log
git commit -m "add app.js"

Git Log

Use command git log to view history of commits made

  • use "ENTER" or up arrow to scroll
  • type "q" in CLI to get out

Git Checkout

  • Use to go back to previous version
git checkout [hashid]

// Back to current version
git checkout master
  • Master ("branch master"): current version; Head: version we are at
  • HEAD Master O -> O -> O -> O

Revert git repo to a previous commit

  • [CLI] git revert --no-commit [hashid]..HEAD
  • [CLI] git commit

Cloning and Github Intro

  • What is Github?
  • Cloning an existing repo

Pushing to Github

  • Creating a repo on github
  • Adding a remote
  • Pushing to github