Date post: | 18-Dec-2014 |
Category: |
Technology |
Upload: | betclic-everest-group-tech-team |
View: | 988 times |
Download: | 0 times |
Let’s Git It !
MAXIME LEMAITRE – 11/09/2014
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”
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
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
Git ConceptsDistributed vs. Centralized
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.
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.
Git ConceptsData 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
Git Concepts
Nearly Every Operation Is Local (Browse History, Commit, Branching, …). No need to be online. Very efficient and fast
Git Has IntegrityEverything 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 snapshotCommitted means that the data is safely stored in your local database.
Basic Git ActionsClone 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.CommitWhen committing in Git, you save your code to your local repository, which then is versioned.PushWhen 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.FetchWhen 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.
Git Demotry 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
Git ConceptsBranching, 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 …
Git ConceptsBranching workflow
Standard workflow (Local branches)
1 2
3 4
Git ConceptsAdvanced Branching workflow
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)
Working with GitGit and/or TFS ?
* Source Repos : Team Foundation Version Control or Git
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
Working with GitGitHub, 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 20141 – twbs/bootstrap2 – jquery/jquery3 – joyent/node4 – mbostock/d3.js5 - angular/angular.js
Working with GitGit Shell/Bash
Command line is the standard way to use git.
Even if there are GUI tools, you will have to use it at least once !
Explorer extensions allow you to work direclty in any folder..
Working with GitGitHub for Windows
Easiest way to use GitHub on Windows.https://windows.github.com/
Working with GitGit and Visual Studio
• Visual Studio 2013 includes Git tools by default– Previously it requires an extension
Work with Visual Studio on OSS projects !
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
Remember to Follow project guidelines !
Pull requests = Commit + Comments + (issue ?)
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
Questions
References
• https://try.github.io/ • http://nvie.com/posts/a-successful-git-branching-model/• http://git-scm.com/ • http://johanleino.wordpress.com/2013/09/18/tfs-vs-git-or-is-it-tfs-with-git/ • http://www.slideshare.net/danielpcox/six3-getting-git • http://spring.io/blog/2010/12/21/social-coding-in-spring-projects • http://hashrocket.com/blog/posts/x-men-days-of-future-past-explained-in-git• http://gitready.com/ • http://stackoverflow.com/tags/git/info