In one of our weekly training, we’ve talked about Git. Here is a quick overview of the main concepts, basic commands and branching strategy, how to work with Git, how to contribute to an OSS project, …
2. Agenda
• Back to basis
• What is that GIT/git/Git thing ?
• Git Concepts
• Demos
• Working with Git
– GitHub
– Git + TFS
– Git Tools for on Visual Studio
• Why Git ?
• Questions
“Git is a free and open
source distributed version
control system designed to
handle everything from
small to very large projects
with speed and efficiency”
3. What’s a version control system ?
“An application that allows you to record changes to
your codebase in a structured and controlled fashion”
• Makes it way easier to undo errors / roll back to earlier versions of code
• Makes it way easier to share a codebase between developers without
creating conflicts
• Makes it way easier to deploy changes from development to staging or
production environments
4. What is that GIT/git/Git thing?
• Distributed Version Control System (DVCS)
• Open source, free (GNU GPL V2)
• Originally developed by Linus Torvalds for the development
of the Linux Kernel in 2005
• Used by a lot of public/private projects
• Focus on speed and efficiency
• Quite a unique design and therefore sometimes a bit scary
and difficult to understand
5. Git Concepts
Distributed vs. Centralized
Centralized version control systems are based on
the idea that there is a single central copy of your
project somewhere (probably on a server), and
programmers will “commit” their changes to this
central copy.
Distributed Version Control systems do not
necessarily rely on a central server to store all the
versions of a project’s files. Instead, every developer
“clones” a copy of a repository and has
the full history of the project on their own hard
drive. This copy (or “clone”) has all of the metadata
of the original.
6. Git Concepts
Data Storage
Most VCSs tend to store data as
changes to a base version of each
file.
But Git stores data as snapshots of
the project over time. Git thinks of
its data more like a set of snapshots
of a mini filesystem
7. Git Concepts
Nearly Every Operation Is Local
(Browse History, Commit, Branching, …).
No need to be online. Very efficient and
fast
Git Has Integrity
Everything is check-summed (SHA-1), it’s
impossible to change the contents of any file
or directory without Git knowing about it
Git Generally Only Adds Data.
Objects (blob, tree, commit, tag, ..) are
immutable but references (branche, remote,
…) always changes.
Your files can reside in 3 states
Modified means that you have changed
the file but have not committed it to your
database yet.
Staged means that you have marked a
modified file in its current version to go
into your next commit snapshot
Committed means that the data is safely
stored in your local database.
8. Basic Git Actions
Clone
A clone is a copy of a repository that lives on your computer instead of on a website's server
somewhere. With your clone you can edit the files in your preferred editor and use Git to keep
track of your changes without having to be online. It is connected to the remote version so that
changes can be synced between the two.
Commit
When committing in Git, you save your code to your local repository, which then is versioned.
Push
When you push your code in Git, it means that you send your changes to the repository on the
server ; after a push, your changes will also be available for other consumers of the central
repository.
Fetch
When a fetch in Git is performed, you get an overview of changes on the central repository, you
can see a list of changes made to the code and decide if you want to get the latest version.
Pull
When a pull is performed, you get the latest version of the server’s repository, with all other
changes of other team members, a merge is automatically performed, although as far as Git can
handle the differences.
9. Git Demo
try it at https://try.github.io/
// init a Git repository
$ git init
// start tracking changes made to all txt files => add them to the
staging area
$ git add '*.js'
// Store our staged changes (current version)
$ git commit -m 'Add all the js files'
// add a remote remote repository (named origin)
$ git remote add origin https://github.com/toto/mysuperproject.git
// push local changes (commits) to the remote repo(branch master)
$ git push -u origin master
// pull down any new changes made by other people
$ git pull origin master
10. Git Concepts
Branching, Killer-feature
• Branching is very cheap
• Branching operations (creation,
deletion, merge) are always local
• You can have multiple local
branches that can be entirely
independent of each other
• Git encourages a workflow that
branches and merges often, even
multiple times in a day
be sure to be on master branch …
// Switched to a new branch "fixes“
$ git checkout –b hotfix
// fix code
// commit staged changes (the fix)
$ git commit -m ‘Fixed hard coded
password'
// return to master
$ git checkout master
// merge local hoxfix branch to master
$ git merge hotfix
// delete local hoxfix branch
$ git branch -d hotfix
// push merged fixed …
13. Git Concepts
Git Hooks
• Hooks are executables scripts that executed before or after important
events
– commit, push, merge, checkout, receive…. (client/server)
• Built-in feature - no need to download anything, run locally.
• Only limited by developer's imagination. Some example :
– Deploy a web site
– Check commit message
– We want to run test suite to run automatically every time we change something
– We want to make sure that our test coverage is high enough
• …
(GitHub doesn’t support fully support hooks, but provide WebHooks and
Services)
14. Working with Git
Git and/or TFS ?
* Source Repos : Team Foundation Version Control or Git
15. Git for TFS users
Git Actions TFS Command
Clone Create Workspace and Get Latest
Checkout Switch workspace / branch
Commit CheckIn / Shelve
Status Pending Changes
Push CheckIn
Pull Get Latest Version
Sync CheckIn and Get Latest Version
16. Working with Git
GitHub, Social Coding
• Basically a Git repository hosting service…
but it Provides a web-based graphical
interface, desktop app for Mac, Linux,
Windows
• Adds many of its own features : issues,
milestones, labels, wiki, API, team
planning, graphs, …
• Unlimited number of public repositories
& collaborators
• For private projects, you have to pay
• You can clone any public repository,
follow projects and developers, post
comments, …
10 Million Repositories (end of 2013)
Most Starred, May 2014
1 – twbs/bootstrap
2 – jquery/jquery
3 – joyent/node
4 – mbostock/d3.js
5 - angular/angular.js
17. Working with Git
Git Shell/Bash
Explorer extensions allow
you to work direclty in any
folder..
Command line is the
standard way to use git.
Even if there are GUI tools,
you will have to use it at
least once !
18. Working with Git
GitHub for Windows
Easiest way to use GitHub
on Windows.
https://windows.github.com/
19. Working with Git
Git and Visual Studio
• Visual Studio 2013 includes Git tools by default
– Previously it requires an extension
Work with Visual Studio on OSS projects !
20. How to contribute to an OSS Project ?
Fork & Pull workflow
Pull requests let you tell others about changes you've pushed
to a GitHub repository. Once a pull request is sent, interested
parties can review the set of changes, discuss potential
modifications, and even push follow-up commits if necessary
Pull requests = Commit +
Comments + (issue ?)
Remember to Follow project guidelines !
21. Why Git ?
• Decentralized Allow developers to work offline, look in history, commit
some changes and create branchs
• It’s extremely fast as nearly everything is local
• Local Branching and merging is cheap
• Perfectly suited for Open Source projects and use by many leaders
• Tool extremely flexible, can support a wide, wide variety of developer
workflows
• Huge community
• Because of GitHub