Git Commands Every Developer Should To Know? - PowerPoint PPT Presentation

About This Presentation
Title:

Git Commands Every Developer Should To Know?

Description:

Git is an important part of daily programming (especially if you're working with a team) and is widely used in the software industry. Since there are many various commands you can use, mastering Git takes time. But some commands are used more frequently (some daily). So in this post, I will share and explain the most used Git commands that every developer should know. Note: To understand this PDF, you need to know the basics and advance of Git. – PowerPoint PPT presentation

Number of Views:5
Slides: 68
Provided by: 9series
Tags:

less

Transcript and Presenter's Notes

Title: Git Commands Every Developer Should To Know?


1
GIT COMMANDS EVERY DEVELOPER SHOULD TO KNOW?
https//www.9series.com/
2
WHAT IS GIT??
3
WHAT 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.
4
GIT features
5
GIT FEATURES
  1. Tracks history
  2. Free and open source

03 Creates backups
GIT features
  1. Branching is easier
  2. Distributed development. Many More...

6
Git 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
7
Git Basic
Clone with HTTPs section git clone
https//github.com/abc/Git-Example.git
8
Git Basic
Clone with HTTPs section git clone
https//github.com/abc/Git-Example.git
Cloning to a specific folder git clone ltrepogt
ltdirectorygt
9
Git 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
10
Git Basic
git clone -branch git clone -branch new_feature
git//remoterepository.git
11
Git 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
12
Git 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
13
Git Basic
Clone the Repo token git clone
https//lttokengt_at_github.com/ltusernamegt/ltrepositorygt
.git
14
Git 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.
15
HOME WORK
One question
16
HOME WORK
One questions Clone multiple git repositories in
one local directory?
17
Git
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.
18
GIT 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
19
GIT 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,
20
GIT BASIC COMMANDS
Git branch The git branch command lets you
create, list, rename, and delete branches
21
GIT 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"
22
GIT 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
23
GIT BASIC COMMANDS
Creating a new branch commit and push git
commit git push -u ltremotegt ltbranch-namegt
24
GIT BASIC COMMANDS
Viewing branches git branch or git branch --list
25
GIT BASIC COMMANDS
Deleting a branch git branch -d ltbranch-namegt
26
GIT BASIC COMMANDS
Git checkout git checkout ltname-of-your-branchgt
27
GIT BASIC COMMANDS
Git Pull git pull ltremotegt
28
GIT BASIC COMMANDS
Git revert A safer way that we can commits is by
using git revert.
undo our
git revert 3321844
29
GIT 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
30
GIT 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
31
GIT 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.
32
GIT 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
33
GIT 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.
34
GIT 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.
35
GIT 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.
36
GIT 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.
37
GIT 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.
38
WHAT IS GIT DIFF COMMAND?
39
WHAT 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

40
WHAT IS GIT DIFF COMMAND?
41
WHAT IS GIT DIFF COMMAND?
  1. 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.
  2. 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.
  3. 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 .
  4. 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_
  5. 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.

42
WHAT IS GIT DIFF COMMAND?
43
DO YOU KNOW SOURCETREE??
44
DO YOU KNOW SOURCETREE??
SourceTree is a graphical user interface (GUI)
desktop that allows users to simplify how they
interact with Git repositories.
45
DO 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
46
GIT HOOKS
47
GIT 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.
48
GIT HOOKS
49
GIT HOOKS
50
GIT HOOKS
  • READ MORE
  • https//www.atlassian.com/git/tutorials/git-hooks

51
GIT BISECT
52
GIT BISECT
The Git bisect command helps you to find bad and
good commits.
53
GIT 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
54
GIT BLAME
55
GIT 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
56
WHAT IS ALTERNATIVE FOR GIT?
57
WHAT 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 ...
58
WHAT 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...
59
Now 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
60
Now 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
61
Using Smart Commits
JIRA/BITBUCKET
62
Using 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
63
Using 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
64
Using Smart Commits
JIRA/BITBUCKET OutPut
65
Using 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
66
QUESTION ANSWER
https//www.9series.com/
67
THANKS YOU FOR ATTENDING
THIS SESSION
https//www.9series.com/
Write a Comment
User Comments (0)
About PowerShow.com