Title: Git Commands Every Developer Should To Know?
1GIT COMMANDS EVERY DEVELOPER SHOULD TO KNOW?
https//www.9series.com/
2WHAT IS GIT??
3WHAT IS GIT??
Git is free and open source software for
distributed version control tracking changes in
any set of files, usually used for coordinating
work among programmers collaboratively
developing source code during software
development. Git means that a local clone of the
project is a complete version control
repository. These fully functional local
repositories make it easy to work offline or
remotely.
4GIT features
5GIT FEATURES
- Tracks history
- Free and open source
03 Creates backups
GIT features
- Branching is easier
- Distributed development. Many More...
6Git Basic
Git clone Git clone is a command for downloading
existing source code from a remote repository
(like Github, for example). In other words, Git
clone basically makes an identical copy of the
latest version of a project in a repository and
saves it to your computer. git clone
lthttps//name-of-the-repository- linkgt Cloning
a local or remote repository Cloning a bare
repository Using shallow options to partially
clone repositories Git URL syntax and supported
protocols
7Git Basic
Clone with HTTPs section git clone
https//github.com/abc/Git-Example.git
8Git Basic
Clone with HTTPs section git clone
https//github.com/abc/Git-Example.git
Cloning to a specific folder git clone ltrepogt
ltdirectorygt
9Git Basic
Clone with HTTPs section git clone
https//github.com/abc/Git-Example.git
Cloning to a specific folder git clone ltrepogt
ltdirectorygt
Cloning a specific tag git clone --branch lttaggt
ltrepogt
10Git Basic
git clone -branch git clone -branch new_feature
git//remoterepository.git
11Git Basic
git clone -branch git clone -branch new_feature
git//remoterepository.git
git clone --template git clone ltrepogit clone
--template lttemplate_directorygt ltrepo
locationgt ltdirectorygt
12Git Basic
git clone -branch git clone -branch new_feature
git//remoterepository.git
git clone --template git clone ltrepogit clone
--template lttemplate_directorygt ltrepo
locationgt ltdirectorygt
git clone git_at_remote.git git clone
https//username_at_github.com/username/repository.gi
t git clone https//usernamepassword_at_github.com/u
sername/repository.git
13Git Basic
Clone the Repo token git clone
https//lttokengt_at_github.com/ltusernamegt/ltrepositorygt
.git
14Git Basic
Clone the Repo token git clone
https//lttokengt_at_github.com/ltusernamegt/ltrepositorygt
.git Other many why to you can clone your git
projects.
15HOME WORK
One question
16HOME WORK
One questions Clone multiple git repositories in
one local directory?
17Git
Providers
GitHub Cloud GitHub On premises Bitbucket GitLab
Cloud GitLab On premises Azure DevOps
Git Atlassian Stash (old version of Bibucket
Server) Other many providers is available in
market.
18GIT CONFIG
git set username and email git config user.name
"Hitesh" git config user.email "abc_at_gm.co" git
config credential.helper store Note You need to
store global git config then you can use bllow
command. git config --global user.name /
user.email
19GIT BASIC COMMANDS
Git clone git clone is primarily used to point to
an existing repo and make a clone or copy of
that repo at in a new directory,
20GIT BASIC COMMANDS
Git branch The git branch command lets you
create, list, rename, and delete branches
21GIT BASIC COMMANDS
Creating a new branch commit and push git
branch ltbranch-namegt git status git add README.md
git add --all git commit -m "Editing the README
to try out git add/commit"
22GIT BASIC COMMANDS
Short status flags are
Short status flags are ?? - Untracked files A -
Files added to stage M - Modified files D -
Deleted files R - Renamed C - Copied U - Updated
but unmerged F - Force Push. Other many short
flags
23GIT BASIC COMMANDS
Creating a new branch commit and push git
commit git push -u ltremotegt ltbranch-namegt
24GIT BASIC COMMANDS
Viewing branches git branch or git branch --list
25GIT BASIC COMMANDS
Deleting a branch git branch -d ltbranch-namegt
26GIT BASIC COMMANDS
Git checkout git checkout ltname-of-your-branchgt
27GIT BASIC COMMANDS
Git Pull git pull ltremotegt
28GIT BASIC COMMANDS
Git revert A safer way that we can commits is by
using git revert.
undo our
git revert 3321844
29GIT BASIC COMMANDS
Git merge First you should switch to the dev
branch git checkout dev Before merging, you
should update your local dev branch git fetch
30GIT ADVANCE COMMANDS
git stash
This Git command temporarily stores your modified
files. You can work in stashed with the
following Git command. git stash Usage And you
can view all of your stashes with the following
command git stash list And if you need a apply
a stash to a branch, simply use apply git stash
apply
31GIT ADVANCE COMMANDS
git rebase
Git rebase similar to the git merge command. It
integrates two branches into a single branch with
one exception. A git rebase command rewrites the
commit history.
32GIT ADVANCE COMMANDS
git rebase
Git rebase similar to the git merge command. It
integrates two branches into a single branch
with one exception. A git rebase command
rewrites the commit history. Usage You should
use the Git rebase command when you have multiple
private branches to consolidate into a single
branch. And it will make the commit history
linear. git rebase ltbasegt
33GIT ADVANCE COMMANDS
git cherry-pick
Git cherry-pick is a helpful command. It's a
robust command and allows you to pick any commit
from any branch and apply it to any other
branch. Usage git cherry-pick
ltcommit-hashgt Git cherry-pick doesnt modify the
history of a repository instead, it adds to the
history.
34GIT ADVANCE COMMANDS
git archive
Git archive command will combine multiple files
into a single file. It's like a zip utility, so
it means you can extract the archive files to
get individual files. Usage git archive --format
zip HEAD gt archive-HEAD.zip It will create a zip
archive of the current revision.
35GIT ADVANCE COMMANDS
Rewriting history change with amend
Git commit --amend and other methods of rewriting
history Changing the Last Commit git commit
--amend git commit --amend -m "an updated commit
message" git push -f gt Its use to this is
latest code source branch if this command you
cant use then getting error link merge or
rebase.
36GIT ADVANCE COMMANDS
Git tracks changes
git reset --hard git reset --hard
ltSOME-COMMITgt The --hard option is used in
order to reset the files of the index (or the
staging area) and of the working directory. --
hard which will completely destroy any changes
and remove them from the local directory.
37GIT ADVANCE COMMANDS
Git tracks changes
git reset --soft HEAD_at_1 which will keep your
files, and stage all changes back
automatically. git reset --mixed HEAD_at_1 which
is the default, and keeps all files the same but
unstages the changes. This is the most flexible
option, but despite the name, it doesnt modify
files. git commit -m "Reverting to the state of
the project at f414f31" git push -f gt Its use
to this is latest code source branch if this
command you cant use then getting error link
merge or rebase.
38WHAT IS GIT DIFF COMMAND?
39WHAT IS GIT DIFF COMMAND?
- Diff command is used in git to track the
difference between the changes made on a file. - Diff Command will produce the changes in all the
files that are present. For the changes on some
specific files only, type the name of the file
after the command name. - git diff
- git diff filename
40WHAT IS GIT DIFF COMMAND?
41WHAT IS GIT DIFF COMMAND?
- The first line shows the file names that have
been considered as the input in git diff. You
can see that they have been marked by a and b
along with the two different file state that has
been taken as input. - This line is not of use. This shows the metadata
related to the command and the execution of it
on the files. As you must be aware by our
discussion in Dot Git folder, this is the object
hash value required by Git for internal use. - This line defines the symbol, called a legend, to
tell you what is used to describe the first file
and what is used to describe the second file. As
you can see, - is used in front of the first
file, and is used in front of the second file.
So whenever diff shows you the changes related to
the first file, they will be marked by - and the
changes in the second file will be marked by the
symbol . - The fourth line shows you symbol _at__at_ and symbols
ahead of it. They are called chunks. Chunks in
git diff define the change' summary. In our image
below the following chunk can be seen _at__at_ -1,2 1
_at__at_ - This means that lines one and two were changed in
the first file and line one was changed in the
second file. Remember the - and symbol used in
the third point as a symbol to the first and
second file respectively.
42WHAT IS GIT DIFF COMMAND?
43DO YOU KNOW SOURCETREE??
44DO YOU KNOW SOURCETREE??
SourceTree is a graphical user interface (GUI)
desktop that allows users to simplify how they
interact with Git repositories.
45DO YOU KNOW SOURCETREE??
SourceTree is a graphical user interface (GUI)
desktop that allows users to simplify how they
interact with Git repositories. Supported OS Mac
OS X Windows
46GIT HOOKS
47GIT HOOKS
If you want to perform custom actions when a
certain event takes place in a Git repository,
hooks are your tool of choice. They let you
normalize commit messages, automate testing
suites, notify continuous integration systems,
and much more. After this article, youll
understand the many ways in which Git hooks can
streamline your workflow.
48GIT HOOKS
49GIT HOOKS
50GIT HOOKS
- READ MORE
- https//www.atlassian.com/git/tutorials/git-hooks
51GIT BISECT
52GIT BISECT
The Git bisect command helps you to find bad and
good commits.
53GIT BISECT
The Git bisect command helps you to find bad and
good commits. To start the git bisect git
bisect start let git bisect know about a good
commit git bisect good a123 let git bisect know
about a bad commit git bisect bad z123
54GIT BLAME
55GIT BLAME
If you need to examine the content of any file
line by line, you need to use git blame. It
helps you to determine who made the changes to a
file. git blame ltyour_file_namegt
56WHAT IS ALTERNATIVE FOR GIT?
57WHAT IS ALTERNATIVE FOR GIT?
SVN (Subversion) Subversion exists to be
universally recognized and adopted as an
open-source, ... Mercurial Mercurial is dedicated
to speed and efficiency with a sane user
interface. It ...
58WHAT IS ALTERNATIVE FOR GIT?
Perforce Perforce Visibility, access control,
workflow and code management for Git
environments. ... Bazaar Bazaar is a version
control system that helps you track project
history over time and to collaborate easily with
others. Other Many more...
59Now what is the base git practice in live
projects
GITLAB (REPO.9SPL.COM)
01 02 03 04 05 06
Create Issue (As per the working on task details
Create MR (Merge request with add reviewer)
Check out branch
Commit and push code if single commit
After one commit use amend
Reviewer review code and merge MR
60Now what is the base git practice in live
projects
GITHUB/BITBUCKET
01 02 03 04 05 06
Create Branch from base branch.
Check out branch
Commit and push code if single commit
After one commit use amend
Create PR (Pull request with add reviewer)
Reviewer review code and merge PR
61Using Smart Commits
JIRA/BITBUCKET
62Using Smart Commits
JIRA/BITBUCKET Syntax ltISSUE_KEYgt ltCOMMAND_1gt
ltoptional COMMAND_1_ARGUMENTSgt ltCOMMAND_2gt
ltoptional COMMAND_2_ARGUMENTSgt ... ltCOMMAND_ngt
ltoptional COMMAND_n_ARGUMENTSgt
63Using Smart Commits
JIRA/BITBUCKET Multiple commands on a single
issue ltISSUE_KEYgt ltCOMMAND_1gt ltoptional
COMMAND_1_ARGUMENTSgt ltCOMMAND_2gt ltoptional
COMMAND_2_ARGUMENTSgt ... ltCOMMAND_ngt ltoptional
COMMAND_n_ARGUMENTSgt Example JRA-123 time 2d 5h
comment Task completed ahead of schedule
resolve
64Using Smart Commits
JIRA/BITBUCKET OutPut
65Using Smart Commits
JIRA/BITBUCKET Multiple commands on multiple
issues ltISSUE_KEY1gt ltISSUE_KEY2gt ... ltISSUE_KEYngt
ltCOMMAND_1gt ltoptional COMMAND_1_ARGUMENTSgt
ltCOMMAND_2gt ltoptional COMMAND_2_ARGUMENTSgt ...
ltCOMMAND_ngt ltoptional COMMAND_n_ARGUMENTSgt Examp
le JRA-123 JRA-234 JRA-345 resolve time 2d 5h
comment Task completed ahead of schedule
66QUESTION ANSWER
https//www.9series.com/
67THANKS YOU FOR ATTENDING
THIS SESSION
https//www.9series.com/