This document provides an overview of version control systems and introduces the basics of using Git. It begins with explaining why version control is useful for collaboration and keeping backups of projects over time. It then contrasts centralized and distributed version control systems, using Subversion and Git as examples. The document goes on to describe some key Git concepts like snapshots, the three main states files can be in, and the basic Git workflow and commands for setting up a repository, tracking and committing changes. It concludes with some references for learning more about Git.
3. S01E01
• Working together
• Archive versions
• Make backup
• Restore to a previous version
• …
We have some problems while
developing projects!
4. S01E01
• Do nothing
• Make an archive file in each version
• You say
• Use a Version Controller System
What we can do ?
5. S01E01
A system that records changes to a file
or set of files over time so that you can
recall specific versions later
What is Version Controller ?
6. S01E01
• Collaboration
• Storing Versions (Properly)
• Restoring Previous Versions
• Understanding What Happened
• Backup
Why Use a Version Control System?
9. S01E02
• It is easy to understand.
• You have more control over users and access
(since it is served from one place).
• More GUI & IDE clients (Subversion has been
around longer).
• Simple to get started.
Centralized V.C. benefits
10. S01E02
• Dependent on access to the server.
• Hard to manage a server and backups (well, not
with Beanstalk of course!)
• It can be slower because every command
connects to the server.
• Branching and merging tools are difficult to use.
Centralized V.C. drawbacks
12. S01E02
• More powerful and detailed change tracking,
which means less conflicts.
• No server necessary – all actions except
sharing repositories are local (commit offline).
• Branching and merging is more reliable, and
therefore used more often.
• It’s fast.
Distributed V.C. benefits
13. S01E02
• The distributed model is harder to understand.
• It’s new, so not as many GUI clients.
• The revisions are not incremental numbers,
which make them harder to reference.
• It can be easier to make mistakes until you are
familiar with the model.
Distributed V.C. drawbacks
15. S02E01
Short Story
Linux kernel is an open source software project:
• 1991–2002, changes to the software were
passed around as patches and archived files.
• 2002, the Linux kernel project began using a
proprietary DVCS called BitKeeper.
• In 2005, the relationship between the
community that developed the Linux kernel
and the commercial company that
developed BitKeeper broke down
16. S02E01
Short Story
• Linus Torvalds prompted to develop their
own tool based on some of the lessons they
learned while using BitKeeper.the goals of
the new system was :
• Speed
• Simple design
• Strong support for non-linear development (thousands of
parallel branches)
• Fully distributed
• Able to handle large projects like the Linux kernel efficiently
(speed and data
18. S02E01
Snapshots, Not Differences
• Most other systems store information as a
list of file-based changes.
• Git basically takes a picture of what all your
files look like at that moment and stores a
reference to that snapshot.
25. S02E02
Staged
Staged means that you have marked a modified
file in its current version to go into your next
commit snapshot.
In simple terms this means that git knows about the change, but it is
not permanent in the repository.
26. S02E02
Three main sections of a Git project
• The Git directory
• The working directory
• The staging area
27. S02E02
The Git directory
The Git directory is where Git stores the
metadata and object database for your project.
29. S02E02
The Staging area
Generally contained in your Git directory, that
stores information about what will go into your
next commit.
A magical place where selected files will be turned into stone with your wizardry and
can be magically transported to the repository at your whim.
30. S02E02
• You modify files in your working directory.
• You stage the files, adding snapshots of them to
your staging area.
• You do a commit (in Git directory)
Git workflow in simple terms
32. S03E01
Installing
You can download Git release from
http://git-scm.com/download
Git is opensource.You can find repository on Github in http://github/git/git
33. S03E01
Command Line or GUI?
There are a lot of different ways to use git:
Original command line tools
Graphical user interfaces
36. S03E01
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
First-Time Git Setup
First set your user name and email address:
37. S03E01
Getting a Git Repository
You can done this in two method:
• Initializing a Repository in an Existing Directory
$ git init
• Cloning an Existing Repository
$ git clone https://github.com/libgit2/libgit2
38. S03E01
Recording Changes to the Repository
Each file in your working directory can be in one
of two states:
• Tracked
• Tracked files are files that were in the last snapshot; they can be
unmodified, modified, or staged.
• Untracked
• Untracked files are everything else – any files in your working
directory that were not in your last snapshot and are not in your
staging area
40. S03E01
Staging Modified Files
You can stage a file with this command:
$ git add
git add is a multipurpose command – you use it to begin tracking new files, to
stage files, and to do other things like marking merge-conflicted files as resolved.
41. S03E01
Committing Your Changes
After staging your files,Now time to commit
$ git commit
Basically git commit "records changes to the repository"
42. S03E01
Remote name
Remote name is basically a bookmark that help
you to manage your remote repositories.
With remote name you can add remote repository url to
local repository and assign a name to it.
Example*:
git git@github.com:git/git.git
http https://github.com/git/git.git
*Git is remote name and git@github.com:git/git.git is remote repository address.
Default remote name is origin
43. S03E01
Git branch
A branch represents an independent line of
development.
$ git checkout <existing-branch>
$ git checkout -b <new-branch>
44. S03E01
Fetching and Pulling from Your Remotes
To get data from your remote projects:
Git fetch
Pulls the data to your local repository – it doesn’t automatically merge it with any of your work
or modify what you’re currently working on.
$ git fetch [remote-name]
Git pull
Automatically fetch and then merge a remote branch into your current branch
$ git pull [remote-name]
45. S03E01
Pushing to Your Remotes
For share your project,you have to push it:
$ git push [remote-name] [branch-name]
Pushing is how you transfer commits from your local repository to a remote repo.
47. S04E01
Some references
• Git official document
https://git-scm.com/doc
• Git simple guide
http://rogerdudler.github.io/git-guide/
• Some useful tutorials
https://www.atlassian.com/git/tutorials/
• Pro Git book
http://book.git-scm.com/
Know better and more
48. The End
“Any fool can know. The point is to understand.”
― Albert Einstein
Thank you