Git Basics


  • Version control is like an unlimited ‘undo’.
  • Version control also allows many people to work in parallel.

Setting Up Git


  • Git and GitHub are not the same thing. Git is an open source version control tool, GitHub is a company that hosts Git repositories in the web and provides a web interface to interact with repos they host.
  • Use git config with the --global option to configure a user name, email address, editor, and other preferences once per machine.
  • Get help with git help

Creating a Repository


  • git init initializes a repository.
  • Git stores all of its repository data in the .git directory.

Tracking Changes


  • git status shows the status of a repository.
  • Files can be stored in a project’s working directory (which users see), the staging area (where the next commit is being built up) and the local repository (where commits are permanently recorded).
  • git add puts files in the staging area.
  • git commit saves the staged content as a new commit in the local repository.
  • Write a commit message that accurately describes your changes.

Exploring History


  • git diff displays differences between commits.
  • git checkout recovers old versions of files.

Ignoring Things


  • The .gitignore file tells Git what files to ignore.

Remotes in GitHub


  • A local Git repository can be connected to one or more remote repositories.
  • Authentication to GitHub via the command line can be via HTTPS and SSH - here we used Personal Access Token (PAT)
  • git push copies changes from a local repository to a remote repository.
  • git pull copies changes from a remote repository to a local repository.

Wrap-up


  • Keep a copy of GitHub cheat-sheet handy when starting out. PDF copy
  • GitHub Docs pages is your go-to for extensive documentation.