Learning version control using Git



Learning version control using Git

1 4


git-intro

Learning version control with git

On Github CuriousLearner / git-intro

Learning version control using Git

Created by Sanyam Khurana / @ErSanyamKhurana / @CuriousLearner

Daily Tasks as Programmer

  • Create “Things”
  • Save “Things”
  • Edit “Things”
  • Save “Things” AGAIN!

Naive method have version control

Problems in naive method

  • No one knows who changed what
  • We created duplicate copies of same thing (wasting space)
  • No one took time to note what was exactly changed

What we wanted to do? - SAVE THINGS AGAIN

  • Who did it?
  • Why they did it?
  • What exactly was changed?
  • We want to keep track of history

Version Control comes to rescue

  • Method to track changes to file(s) and folder(s) and your binaries.
  • Who changed what and why? - via commit messages
  • Non-Distributed [Centralized] – Subversion, CVS
  • All commit goes to centralized master repo
  • Distributed – Git, Mercurial
  • Commit goes to remote repo but everyone has a copy (clone)

Why Git?

  • You can use git even when you're offline
  • Code revisions (commit) that you made would be available to only you locally unless you push to remote repo.
  • Create branches, work locally, isolate your work and merge seamlessly.
  • It takes snapshots of changes and treat files as stream of snapshots over time.

  • It compresses the .git contents
  • It has integrity
  • The mechanism that Git uses for this checksumming is called a SHA-1 hash. This is a 40-character string composed of hexadecimal characters (0–9 and a–f) and calculated based on the contents of a file or directory structure in Git. A SHA-1 hash looks something like this:
    24b9da6552252987aa493b52f8696cd6d3b00373

  • You will see these hash values all over the place in Git because it uses them so much. In fact, Git stores everything in its database not by file name but by the hash value of its contents.

Git Workflow

Obtain Repo
git init
git clone
Make Changes
Stage Changes
git add {filename}
Commit Changes
git commit -m “Commit message”
Push Changes to Remote Repo
git push {remote_name} {repo_name}

Demo

  • Config
  • Cloning
  • Forking
  • Branching
  • Remote
  • Checkout
  • Pull
  • Push
  • Pull Requests

A bit about git internals

  • Commits are actually SHA1 hashes that creates the distinction
  • All commits in repo are nodes of a tree
  • .git folder contains:
    • config – Configuration files
    • logs/* - All the logs for commits
    • objects/* - The object repository
    • refs/remotes/* - tracking other remotes
    • Index – index cache (staging area)
    • HEAD – points to the latest commit on current branch

Where to go from here?

That moment when you know the power of Git

THE END

Questions?

Shout out on Twitter: @ErSanyamKhurana Shoot a mail at: Sanyam@MozPacers.org

Learning version control using Git Created by Sanyam Khurana / @ErSanyamKhurana / @CuriousLearner