GDG LAGOS
Getting Deep with Git
What is Git and why all the 'hype'?
Feel free to ask your questions!
A bit of a background
Git was created in 2007 by Linus Torvalds ...
A bit of a background
I said 'a bit' ...
see wikipedia
What is Git?
Simply put, git is a source code management system.
Source control / Version control is the management of changes to documents, computer programs and other collections of information
see wikipedia article for more!
Git makes your life easier
Yes, it does!
Has this ever happened to you?
Now you don't need to worry about it!
That in itself is a winner for version control.
Some more benefits of git
Data redundancy and replication
Since there are multiple full repositories on multiple machines (instead of one central repository), the risk of project loss due to server failure or some other catastrophe is much lower.
High Availability
High availability -- Server down? Network down? No problem. Work in your repo (commit, view history, branch, etc) to your heart's content. Try that with Subversion!
One central .git directory
Only one .git directory per repository -- Versus a .svn in every subfolder, which, as you may know from painful personal experience, can lead to problems.
This might not seem like a benefit but ask those that used other version control systems
Superior disk utilization and network performance
Git efficiently compresses the objects in the .git directory, saving you space.
Collaboration Friendly
Git makes it easy to collaborate on projects with groups of contributors. And with great services like Github, Git's collaboration friendliness is even further magnified.
Installing Git
Windows
Installing Git on windows
Mac
Or via the MacPorts
sudo port install git-core +svn +doc +bash_completion +gitweb
Generating SSH keys on Mac
SSH keys are a way to identify trusted computers, without involving passwords everytime you push to Github. The link below will walk you through generating an SSH key and adding the public key to your GitHub account.
Linux
Red Hat based systems (Fedora, CentOS)
yum install git-core
Debian based systems (Ubuntu)
sudo apt-get install git
History
Git is really all about your history.
It creates a specialized filesystem to store your code history and when you tell it to, it records snapshots of your code repository.
Do note that git is a command line tool that has GUI frontends, though very convenient, does not show the full power of git. So once we understand the concepts, we'll move to a gui tool
Configuring Git
$ git config --global user.name "Tunji Bello Ebube"
$ git config --global user.email user@email.com
Some other config values that may be interesting
core.editor => your_editor_name_here
color.ui => true
Initializing a Git repository
Navigate into the folder you'd like git to start tracking and run
$ git init
A Few of my favourite things
- Git branch
- Git add
- Git commit
- Git diff
- Git log
- Git stash
A closer look a branches
A single commit in the repository has the following format
Pointer to that root tree and all the commit metadata
Making some commits to the repository
Many commit trees and their associated metadata
This is how the repository looks at the moment.
Showing the master branch and its representation
When we branch by running
$ git branch testing
We now have our repo looking like...
Multiple branches
HUH?...What is 'HEAD'
Its just a pointer...
We checkout the new branch:
$ git checkout testing
Doing another commit
Showing 'testing' ahead of 'master' by one commit!
Some advanced concepts
- Git objects
- Git log Options
- Git reset
- Git rebase
- Git cherry-pick
Git Objects
Git objects are entirely composed of:
The Git refspec
A refspec maps a branch in the local repository to a branch in a remote repository. This makes it possible to manage remote branches using local Git commands and to configure some advanced git push and git fetch behavior.
src
The pattern for references on the remote side
dst
Where the references will be written to locally
Git Log
Some interesting options:
- --grep
- --author
- --since, --after, --until, --before
- --merges (--min-parents=2)
- --pretty=full