Git - Version Control System
Git - Version Control System
Director/CTO Panacloud
PIAIC
Book we will
follow
What is Version Control System?
❖ Collaboration
➢ Without a VCS in place, you‘re probably working together in a
shared folder on the same set of files.
➢ And you have to coordinate with others so that they don’t work on
same file, it will be very difficult to manage
➢ With a VCS, everybody on the team is able to work absolutely freely
- on any file at any time.
➢ The VCS will later allow you to merge all the changes into a
common version.
Why Use a Version Control System?
❖ Backup
➢ A side-effect of using a distributed VCS like Git is that it can act as
a backup
➢ every team member has a full-blown repository of the project on
his disk
➢ If central server break down (and your backup drives fail), all you
need for recovery is one of your teammates’ local Git repository.
❖ VSS
Different Types
Of Version
Control Systems ❖ SVN
❖ GIT
Microsoft Visual SourceSafe
VSS
(VSS) is a source control
program, oriented towards
small software development
projects.
SVN is the abbreviated form
SVN of “Apache Subversion” and
is a popular version control
system tool. It is a
centralized version control
system
Git is a distributed
version-control system for
tracking changes in source
GIT
code during software
development. It is designed
for coordinating work among
programmers, but it can be
used to track changes in any
set of files.
❖ Centralized Version
Types of Version
Control System (CVCS)
Control Systems
❖ Distributed Version
Control System (DVCS)
Centralized version control
Centralized system (CVCS) uses a
central server to store all files
Version Control
and enables team
System (CVCS) collaboration. It works on a
single repository to which
users can directly access a
central server.
Every programmer can
Centralized extract or update their
workstations with the data
Version Control
present in the repository or
System (CVCS) can make changes to the
data or commit in the
repository. Every operation is
performed directly on the
repository.
❖ It is not locally available;
meaning you always need to
be connected to a network
CVCS Drawbacks to perform any action.
❖ Since everything is
centralized, in any case of
the central server getting
crashed or corrupted will
result in losing the entire
data of the project.
Distributed
Version Control These systems do not
System (DVCS) necessarily rely on a central
server to store all the
versions of a project file.
In Distributed VCS, every
Distributed contributor has a local copy
or “clone” of the main
Version Control
repository i.e. everyone
System (DVCS) maintains a local repository
of their own which contains
all the files and metadata
present in the main
repository.
Distributed
Version Control
System (DVCS) GIT is Distributed version
Control System
Every programmer maintains
Distributed a local repository on its own,
Version Control which is actually the copy or
System (DVCS) clone of the central
repository on their hard drive.
They can commit and update
their local repository without
any interference
Programmer can update their
Distributed local repositories with new
Version Control data from the central server
System (DVCS) by an operation called “pull”
and affect changes to the
main repository by an
operation called “push” from
their local repository.
Distributed
Version Control All operations (except push &
pull) are very fast because
System (DVCS)
the tool only needs to access
the hard drive, not a remote
Advantages server. Hence, you do not
always need an internet
connection.
Distributed
Version Control Committing new change-sets
can be done locally without
System (DVCS)
manipulating the data on the
main repository. Once you
Advantages have a group of change-sets
ready, you can push them all
at once.
Distributed Since every contributor has a
Version Control full copy of the project
System (DVCS) repository, they can share
changes with one another if
Advantages they want to get some
feedback before affecting
changes in the main
repository.
Distributed
Version Control If the central server gets
System (DVCS) crashed at any point of time,
the lost data can be easily
Advantages recovered from any one of
the contributor’s local
repositories.
Git is a distributed
version-control system for
❖ Go to https://git-scm.com/downloads
❖ Installation Guide:
➢ https://git-scm.com/book/en/v2/Getting-Started-Installi
ng-Git
❖ For Linux:
➢ https://git-scm.com/download/linux
❖ For Windows:
➢ https://git-scm.com/download/win
Installing and Setting Up Git
❖ Go to https://www.syntevo.com/smartgit/download
❖ Download SmartGit
❖ Install SmartGit with all default settings
Basic operations ❖ Initialize
in Git are ❖ Add
❖ Commit
❖ Pull
❖ Push
Advanced Git
operations ❖ Branching
❖ Merging
❖ Rebasing
Git
Operations
❖ Think of a repository as a
kind of database where your
Important Terms VCS stores all the versions
and metadata that
1. Repository accumulate in the course of
your project.
❖ In Git, the repository is just a
simple hidden folder named
“.git” in the root directory of
your project
Important Terms
The root folder of your
project is often called the
2. Working “working copy” (or “working
Directory directory”). It‘s the directory
on your local computer that
contains your project‘s files.
Important Terms
3. File Status
Staging area is a virtual place
Important Terms that collects all the files you
want to include in the next
4. Staging Area commit
❖ Another example
➢ Production, development and feature context
➢ Production code is tested and deployed and we don’t want
any problem in that
➢ Development team is working on new feature and we don’t
want that feature to effect production code until it is properly
tested
➢ All feature combines in development to have final testing
before deployment
❖ Branches are what we
need to solve context
Branches to the problems.
Rescue ❖ Because a branch
represents exactly such a
context in a project and
helps you keep it separate
from all other contexts.
Branches to the Rescue
Branches to the Rescue
❖ All the changes you make at any time will only apply to the
currently active branch; all other branches are left
untouched
❖ This gives you the freedom to both work on different things
in parallel and, above all, to experiment - because you can‘t
mess up!
❖ In case things go wrong you can always go back / undo /
start fresh / switch contexts
Working with Branches
❖ If you have local changes that are not committed and want
discard change then you can use following commands
❖ Discard changes in single file
➢ git checkout HEAD <file/to/restore>
❖ Discard all changes that are not committed (already
learned previously)
➢ git reset --hard HEAD
Demo
Undoing Committed
Changes
Undoing Committed Changes
❖ Merge Commit
❖ In very simple cases, one
Understand of the two branches
doesn‘t have any new
merge first :
commits since the
Fast-Forward branching happened - its
latest commit is still the
common ancestor.
Understand merge first : Fast-Forward
❖ The reason for this is that it now has a new parent commit
(C4, which it was rebased onto, compared to C1, when it
was originally created).
❖ Rewriting history in such a way is unproblematic as long as
it only affects commits that haven‘t been published, yet
❖ If it is published then, some other developer might have
based his work on on original C3, this will make it more and
more complex
The Pitfalls of Rebase
❖ Heading
❖ Styling text
❖ Quoting text
❖ Quoting code
❖ Links
❖ List
❖ Task List
Heading
❖ To create a heading, add
one to six # symbols before
your heading text.
Styling text
❖ You can indicate emphasis
with bold, italic, or
strikethrough text.
Quoting text
❖ You can quote text with a >
Quoting code ❖ You can call out code or a
command within a sentence
with single backticks. The
text within the backticks will
not be formatted.
❖ You can create an inline link
by wrapping link text in
Links brackets [ ], and then
wrapping the URL in
parentheses ( ). You can
also use the keyboard
shortcut command + k to
create a link.
Lists
❖ You can make an unordered
list by preceding one or
more lines of text with - or *
Nested Lists
❖ You can create a nested list
by indenting one or more list
items below another item.
Task lists ❖ To create a task list, preface
list items with a regular
space character followed by
[ ]. To mark a task as
complete, use [x]
Demo
Resources
❖ https://www.amazon.com/Learn-Version-Control-step-step/dp/1
520786506
❖ https://www.git-tower.com/learn/git/ebook
❖ https://git-scm.com/book/en/v2/Git-Branching-Rebasing
❖ http://git-scm.com/book/en/v2/Git-Branching-Remote-Branche#
Tracking-Branches
❖ https://help.github.com/en/articles/basic-writing-and-formatting
-syntax
Zeeshan Hanif
Director/CTO Panacloud
PIAIC