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.
- 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
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
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