this a good start in git usage and it is perfect for beginners after study it. you will be able to start using GITand go to advance usage this from my 7 years of experience git is the power of DevOps
2. Agenda
• What is version control
• Benefits of version control systems
• What is Git
• Distributed Development
• Community
• Install Git on Windows
• Cloning an existing repository: git clone
• Git workflow
• Git terms
• Setting up a repository
• Git usage and commands
3. What is version control
Version control systems are a category of software tools that help a
software team manage changes to source code over time. Version control
software keeps track of every modification to the code in a special kind of
database. If a mistake is made, developers can turn back the clock and
compare earlier versions of the code to help fix the mistake while
minimizing disruption to all team members.
Software developers working in teams are continually writing new source
code and changing existing source code. The code for a project, app or
software component is typically organized in a folder structure or "file tree".
One developer on the team may be working on a new feature while
another developer fixes an unrelated bug by changing code, each
developer may make their changes in several parts of the file tree.
4. Version control helps teams solve these kinds of problems, tracking every
individual change by each contributor and helping prevent concurrent
work from conflicting. Changes made in one part of the software can be
incompatible with those made by another developer working at the same
time. This problem should be discovered and solved in an orderly manner
without blocking the work of the rest of the team. Further, in all software
development, any change can introduce new bugs on its own and new
software can't be trusted until it's tested. So testing and development
proceed together until a new version is ready.
5. Benefits of version control systems
Developing software without using version control is risky, like not having
backups. Version control can also enable developers to move faster and it
allows software teams to preserve efficiency and agility as the team scales
to include more developers.
Version Control Systems (VCS) have seen great improvements over the past
few decades and some are better than others. VCS are sometimes known
as SCM (Source Code Management) tools or RCS (Revision Control System).
One of the most popular VCS tools in use today is called Git. Git is
a Distributed VCS,
6. What is Git
By far, the most widely used modern version control system in the world
today is Git. Git is a mature, actively maintained open source project
originally developed in 2005 by Linus Torvalds, the famous creator of the
Linux operating system kernel. A staggering number of software projects
rely on Git for version control, including commercial projects as well as
open source. Developers who have worked with Git are well represented in
the pool of available software development talent and it works well on a
wide range of operating systems and IDEs (Integrated Development
Environments).
7. characteristics
Performance
The raw performance characteristics of Git are very strong when
compared to many alternatives. Committing new changes,
branching, merging and comparing past versions are all
optimized for performance. The algorithms implemented inside
Git take advantage of deep knowledge about common
attributes of real source code file trees, how they are usually
modified over time and what the access patterns are
8. Security
Git has been designed with the integrity of managed source code
as a top priority. The content of the files as well as the true
relationships between files and directories, versions, tags and
commits, all of these objects in the Git repository are secured with a
cryptographically secure hashing algorithm called SHA1. This
protects the code and the change history against both accidental
and malicious change and ensures that the history is fully traceable.
With Git, you can be sure you have an authentic content history of
your source code.
9. Flexibility
One of Git's key design objectives is flexibility. Git is flexible in
several respects: in support for various kinds of nonlinear
development workflows, in its efficiency in both small and large
projects and in its compatibility with many existing systems and
protocols.
Git has been designed to support branching and tagging as first-
class citizens (unlike SVN) and operations that affect branches
and tags (such as merging or reverting) are also stored as part of
the change history. Not all version control systems feature this
level of tracking.
10. Traceability
Traceability. Being able to trace each change made to the software and
connect it to project management and bug tracking software
11. Git for developers
Feature Branch Workflow
One of the biggest advantages of Git is its branching capabilities. Unlike
centralized version control systems, Git branches are cheap and easy to
merge. This facilitates the feature branch workflow popular with many Git
users.
Feature branches provide an isolated environment for every change to
your codebase. When a developer wants to start working on something—
no matter how big or small—they create a new branch. This ensures that
the master branch always contains production-quality code.
12. Distributed Development
In SVN, each developer gets a working copy that points back to a single
central repository. Git, however, is a distributed version control system.
Instead of a working copy, each developer gets their own local repository,
complete with a full history of commits.
Having a full local history makes Git fast, since it means you don’t need a
network connection to create commits, inspect previous versions of a file,
or perform diffs between commits.
Distributed development also makes it easier to scale your engineering
team. If someone breaks the production branch in SVN, other developers
can’t check in their changes until it’s fixed. With Git, this kind of blocking
doesn’t exist. Everybody can continue going about their business in their
own local repositories.
13. Community
In many circles, Git has come to be the expected version control system for
new projects. If your team is using Git, odds are you won’t have to train
new hires on your workflow, because they’ll already be familiar with
distributed development.
14. Install Git on Windows
Git for Windows stand-alone installer
Download the latest Git for Windows installer.
When you've successfully started the installer, you should see the Git
Setup wizard screen. Follow the Next and Finish prompts to complete the
installation. The default options are pretty sensible for most users.
Open a Command Prompt (or Git Bash if during installation you elected not
to use Git from the Windows Command Prompt).
Run the following commands to configure your Git username and email
using the following commands, replacing Emma's name with your own.
These details will be associated with any commits that you create:
17. Git Terms
Trees
Tree is an object, which represents a directory. It holds blobs as well as other sub-directories. A
tree is a binary file that stores references to blobs and trees which are also named
as SHA1 hash of the tree object.
Commits
Commit holds the current state of the repository. A commit is also named by SHA1 hash. You
can consider a commit object as a node of the linked list. Every commit object has a pointer to
the parent commit object. From a given commit, you can traverse back by looking at the
parent pointer to view the history of the commit. If a commit has multiple parent commits, then
that particular commit has been created by merging two branches.
Branches
Branches are used to create another line of development. By default, Git has a master branch,
which is same as trunk in Subversion. Usually, a branch is created to work on a new feature.
Once the feature is completed, it is merged back with the master branch and we delete the
branch. Every branch is referenced by HEAD, which points to the latest commit in the branch.
Whenever you make a commit, HEAD is updated with the latest commit.
Tags
Tag assigns a meaningful name with a specific version in the repository. Tags are very similar to
branches, but the difference is that tags are immutable. It means, tag is a branch, which
nobody intends to modify. Once a tag is created for a particular commit, even if you create a
new commit, it will not be updated. Usually, developers create tags for product releases.
18. Clone
Clone operation creates the instance of the repository. Clone operation not only checks out
the working copy, but it also mirrors the complete repository. Users can perform many
operations with this local repository. The only time networking gets involved is when the
repository instances are being synchronized.
Pull
Pull operation copies the changes from a remote repository instance to a local one. The pull
operation is used for synchronization between two repository instances. This is same as the
update operation in Subversion.
Push
Push operation copies changes from a local repository instance to a remote one. This is used
to store the changes permanently into the Git repository. This is same as the commit operation
in Subversion.
HEAD
HEAD is a pointer, which always points to the latest commit in the branch. Whenever you
make a commit, HEAD is updated with the latest commit. The heads of the branches are
stored in .git/refs/heads/ directory
19. Repository
A repository contains the history, the different versions over time and all different
branches and tags. In Git each copy of the repository is a complete repository. If the
repository is not a bare repository, it allows you to checkout revisions into your working
tree and to capture changes by creating new commits. Bare repositories are only
changed by transporting changes from other repositories.
Revision
Represents a version of the source code. Git implements revisions as commit
objects (or short commits ). These are identified by an SHA-1 hash
Staging area
The staging area is the place to store changes in the working tree before the commit.
The staging area contains a snapshot of the changes in the working tree (changed or
new files) relevant to create the next commit and stores their mode (file type,
executable bit).
20. Setting up a repository
What is a Git repository?
A Git repository is a virtual storage of your project. It allows you to save
versions of your code, which you can access when needed.
Initializing a new repository: git init
to create a new repo, you'll use the git init s a one-time command you use
during the initial setup of a new repo. Executing this command will create a
new .git subdirectory in your current working directory. This will also create a
new master branch.
21. Cloning an existing repository: git clone
If a project has already been set up in a central repository, the clone
command is the most common way for users to obtain a local
development clone. Like git init cloning is generally a one-time operation.
Once a developer has obtained a working copy, all version control
operations are managed through their local repository.
Git clone url
Saving changes to the repository: git add and git commit
Now that you have a repository cloned or initialized, you can commit file
version changes to it. The following example assumes you have set up a
project at
23. Syncing
git remote
The git remote command lets you create, view, and delete connections to other
repositories. Remote connections are more like bookmarks rather than direct links
into other repositories. Instead of providing real-time access to another
repository, they serve as convenient names that can be used to reference a not-
so-convenient URL.
For example, the following diagram shows two remote connections from your
repo into the central repo and another developer’s repo. Instead of referencing
them by their full URLs, you can pass the origin and john shortcuts to other Git
commands.
24.
25. git fetch
imports commits from a remote repository into your local repo. The resulting
commits are stored as remote branches instead of the normal local
branches that we’ve been working with. This gives you a chance to review
changes before integrating them into your copy of the project.
26. git pull
Merging upstream changes into your local repository is a common task in
Git-based collaboration workflows. We already know how to do this with git
fetch followed by git merge
27. git push
Pushing is how you transfer commits from your local repository to a remote
repo. It's the counterpart to git fetch but whereas fetching imports
commits to local branches, pushing exports commits to remote branches.
This has the potential to overwrite changes, so you need to be careful how
you use it. These issues are discussed below.
28.
29. Git Branch
A branch represents an independent line of development. Branches serve
as an abstraction for the edit/stage/commit process. You can think of them
as a way to request a brand new working directory, staging area, and
project history. New commits are recorded in the history for the current
branch, which
Git branch command lets you create, list, rename, and delete branches. It
doesn’t let you switch between branches or put a forked history back
together again. For this reason results in a fork in the history of the project.
30.
31.
32. Download TortoiseGit
Working with tortoise
Documentation link of it
https://tortoisegit.org/docs/tortoisegit/