SlideShare a Scribd company logo
GIT >> Version Control System
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Version Control System - VCS
Version control is a system that records changes to a file or set of files over time so that you can recall
specific versions later.
▸ It allows you to revert selected files back to a previous state, revert the entire project back to a
previous state, compare changes over time, see who last modified something that might be causing a
problem, who introduced an issue and when, and more.
▸ Using a VCS also generally means that if you screw things up or lose files, you can easily recover.
2
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Local VCS - LVCS
3
Local VCS maintains a simple database that
records all the changes to files under revision
control.
It keeps patch sets (i.e. the difference
between files) in a special format on disk; it
can then re-create what any file looked like at
any point in time by adding up all the patches.
Problem >>
How to collaborate with other developers?
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Centralized VCS - CVCS
Centralized Version Control Systems
(CVCSs) have a single server that
contains all the versioned files, and a
number of clients that check out files
from that central place.
Problem >>
Centralized server is a single point of
failure.
4
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Distributed VCS - DVCS
In a Distributed Version Control Systems (DVCSs)
clients don’t just check out the latest snapshot of the
files; rather, they fully mirror the repository, including
its full history.
if any server dies, and these systems were
collaborating via that server, any of the client
repositories can be copied back up to the server to
restore it. Every clone is really a full backup of all the
data.
5
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
DVCS >> GIT
▸ Git is a distributed version-control system for tracking changes in source 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.
▸ It was created by Linux Development Community (in particular, Linus Torvalds) in 2005 for
development of the Linux kernel when the relationship between the community and the BitKeeper
company broke down.
▸ Git naming:
▹ In British slang, unpleasant person
▹ Global information tracker
▹ Goddamn idiotic truckload of sh*t
6
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT
▸ GIT thinks of its data more like a series of snapshots of a miniature filesystem.
▸ With Git, every time you commit, or save the state of your project, Git basically takes a picture of what
all your files look like at that moment and stores a reference to that snapshot.
▸ To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous
identical file it has already stored.
7
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT >> File States
▸ Each file in the working directory can be in 2 states:
▹ Tracked – files that were in the last snapshot.
▹ Untracked – everything else, not in the last snapshot and not in the staging area.
▸ Tracked file states:
▹ Unmodified/Committed – data is safely stored in the local database.
▹ Modified – you have changed the file but have not committed it to your database yet.
▹ Staged – you have marked a modified file in its current version to go into your next commit snapshot.
8
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT >> Stage and Commit Process
▸ Staging the files computes the checksum for each one, stores that version of
the file in the Git repository and adds that checksum to the staging area.
▸ During git commit, git checksums each subdirectory and stores them as a tree
object in the Git repository.
▸ Git then creates a commit object containing metadata and pointer to the
project tree.
9
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT >> Multiple Commits Process
▸ The scenario of multiple commits.
▸ Each new commit stores a pointer to the commit that came immediately before it.
10
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
11
GIT Command Line
- only place you can run all Git commands
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> First-time Setup
12
▸ Version check: $ git --version
▸ Configuration scope:
▹ --system : values applied to every user on the system and all their repositories.
▹ --global : values specific personally to you and affects all the repositories you work with.
▹ --local : values specific to that single repository you are currently using.
▸ Get/Set Configuration variables :
▹ To view all the settings: $ git config --list
▹ To view all the settings with file path: $ git config --list --show-origin
▹ To check a specific variable value: $ git config <key>
▹ To set a specific variable value: $ git config --global <key> <value>
▸ First time setup:
$ git config --global user.name “username”
$ git config -- global user.email “useremail@gmail.com”
cause every git commit uses your name and email
▸ Getting help: $ git <verb> --help
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Getting a GIT Repository
13
▸ Initialize an existing local directory:
Go within that directory and run - $ git init
▸ Clone an existing remote repository:
To clone the remote repository run - $ git clone <url>
To clone the remote repository into your directory run - $ git clone <url> <new-directory-name>
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Creating a GIT Repository
14
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Check/Add/Remove Remote Repository
15
▸ To show all the remote repositories you have configured
$ git remote –v
▸ To add new remote repositories
$ git remote add <shortname> <url>
git clone command implicitly adds the remote for you
▸ To remove remote repository
$ git remote remove <shortname>
▸ To rename remote repository
$ git remote rename <old-shortname> <new-shortname>
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Fetch/Pull/Push Information
16
▸ To fetch
$ git fetch <remote>
This command only downloads the data to your local repository - it doesn’t automatically merge it.
▸ To pull
$ git pull <remote> <branch>
If your current branch(master) is set up to track a remote branch(remote master), then this command
automatically fetch and then merge that remote branch into your current branch.
▸ To push (pull/fetch before push)
$ git push <remote> <branch>
▸ Inspecting a remote,
$ git remote show <remote>
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> How git fetch Works
17
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> How git fetch Works
18
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Recording Repository Changes
19
▸ To get the status of the files
$ git status
▸ To track new file/stage a file
$ git add <file-path>
To add changes from all the tracked and untracked files
$ git add -A
▸ To commit your staged changes (commit records the snapshot you set up in your staging area)
$ git commit –m <commit-message>
To skip the staging area and commit every tracked files(auto staged)
$ git commit –a –m <commit-message>
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Ignoring Specific Files
20
▸ Create a file named .gitignore and
list the file names/patterns that you don’t want GIT to automatically add/even show you as being
untracked.
For example,
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
*.[oa] to ignore any files ending with .o or, .a
!lib.a to track lib.a file even though you are ignoring .a files
/TODO to ignore TODO file in the current directory, not subdirectory
build/ to ignore all files in any directory named build
doc/*.txt to ignore doc/notes.txt file, bit not doc/server/arch.txt, i.e. not within
subdirectory
doc/**/*.pdf To ignore all .pdf files in the doc/ directory and its subdirectory
GIT CLI >> Viewing the Changes
21
▸ To see what you’ve changed but not yet staged (diff. between staged and modified files)
$ git diff
▸ To see what you’ve staged that will go into the next commit (diff. between staged and committed files)
$ git diff --cached
▸ To rename a file in GIT
$ git mv <file_from> <file_to>
▸ To make a tracked file untracked
$ git rm --cached <file-name>
To remove a file from your working directory
$ git rm <file-name>
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Commit History
22
▸ To list all the commits made in the repository in reverse chronological order,
$ git log
▸ To see some abbreviated stats for each commit
$ git log --stat
▸ To see the last 3 commit history
$ git log -3
▸ To see the difference introduced in each commit,
$ git log -p -2
▸ To show each commit in one line
$ git log --oneline
▸ To see the branch and graph history in the form of a graph
$ git log --pretty=format:”%h %s” --graph
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> git log Options
23
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
-<n> Show only the last n commits
--since, --after Limit commits to those made after the specified date
--until, --before Limit the commits to those made before the specified date
--author Only show commits in which the author entry matches the specified string
--committer Only show commits in which the committer entry matches the specified string
--grep Only show commits with a commit message containing the string
-S Only show commits adding or removing code matching the string
GIT CLI >> git log Options
24
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
-p Show the patch introduced in each commit
--stat Show statistics for files modified in each commit
--pretty Show commits in an alternate format. Oneline/short/full/fuller/format
--oneline Shorthand for --pretty=oneline --abbrev-commit
--graph Display an ASCII graph of the branch and merge history beside the log output
%H Commit hash %an, %ae, %ad Author name, email and date
%h Abbreviated commit hash %cn, %ce, %cd Committer name, email and date
%P Parent hashes %s Subject
%p Abbreviated parent hashes
GIT CLI >> Undoing Things
25
▸ To redo the last commit
$ git commit --amend -m “new commit message”
or
$ git commit –amend
▸ To unstage a staged file
$ git reset HEAD <file-name>
▸ To unmodify a modified file
$ git checkout -- <file-name>
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Branching
26
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
▸ To list all the current branches
$ git branch
The * pointed branch indicates the branch currently HEAD points to
▸ To get the list of merged branches
$ git branch –merged
▸ To get the list of unmerged branches
$ git branch –no-merged
▸ To create a new branch
$ git branch <branch-name>
▸ To switch to new branch
$ git checkout <branch-name>
▸ To remove an already merged branch
$ git branch –d <branch-name>
▸ To remove an unmerged branch
$ git branch –D <branch-name>
GIT CLI >> Branching >> initial local repository
27
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Branching >> creating a new branch
28
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
$ git branch <branch-name>
GIT CLI >> Branching >> switching to a new branch
29
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
$ git checkout <branch-name>
GIT CLI >> Branching >> staging & committing in the new branch
30
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
$ git commit –a –m “commit message”
GIT CLI >> Branching >> switching back to master branch
31
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
$ git checkout master
GIT CLI >> Branching >> staging and committing in master branch
32
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
$ git commit –a –m “commit message”
GIT CLI >> Branching >> example-step 1
33
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >> Branching >> example-step 2
34
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Creating a new branch and switching to that branch
$ git checkout -b iss53
or,
$ git branch iss53
$ git checkout iss53
GIT CLI >> Branching >> example-step 3
35
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Committing in that new branch
$ git commit -a –m “commit message”
GIT CLI >> Branching >> example-step 4
36
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Switching back to master, creating new branch hotfix,
switching to that branch and performing a new commit
there
$ git checkout master
$ git checkout hotfix
$ git branch hotfix
$ git commit -a –m “commit message”
GIT CLI >> Branching >> example-step 5
37
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Switching back to branch master and merging with the hotfix branch
$ git checkout master
$ git merge hotfix
GIT CLI >> Branching >> example-step 6
38
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Deleting the hotfix branch, switching to iss53 branch and performing new commit there
$ git branch -d hotfix
$ git checkout iss53
$ git commit –a –m “commit message”
GIT CLI >> Branching >> example-step 7
39
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Going back to master branch
$ git checkout master
GIT CLI >> Branching >> example-step 8
40
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
Merging the master branch with iss53 branch
$ git merge iss53
If conflict occurs, then open and edit the conflicted file
remove the <<<<<<<, =======, >>>>>>> symbols, perform necessary
changes, finally stage and commit the changes
GIT CLI >> Revision Selection
41
▸ To show the details of a specific commit
$ git show <SHA-1 hash value of that commit>
▸ To see the log of where your HEAD and branch references have been for the last few months
$ git reflog
▸ To refer to the older commits from the current HEAD position
$ git show HEAD@{5}
▸ To show the first parent of a specific commit
$ git show HEAD^
To show the second parent(meaning other branch parent) of a specific commit
$ git show HEAD^2
▸ To show the first parent of a first parent
$ git show HEAD~2
▸ Difference between the second branch commits with first branch commits
$ git log br1..br2
▸ Difference between both of the branch commits
$ git log br1…br2
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>Temporarily saving changes at a Branch
42
To switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of
half-done work just so you can get back to this point later. The answer to this issue is the git stash
command.
Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged
changes — and saves it on a stack of unfinished changes that you can reapply at any time (even on a
different branch).
 To save the current work
$ git stash push
 To check all the stashes
$git stash list
 To apply any certain stash changes to the current branch file
$ git stash apply
or, $ git stash apply stash@{2}
 To delete a saved stash from the stack
$ git stash drop stash@{1}
 To apply the stash changes and also delete from the stack at the same time
$ git stash pop stash@{1}
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
43
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
44
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
45
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
46
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
47
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
48
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
49
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
50
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
51
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
GIT CLI >>The Role of Reset
52
Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
53
THANKS!
Any questions?
You can find me at imam@cse.uiu.ac.bd

More Related Content

What's hot (20)

PPTX
Git 101 for Beginners
Anurag Upadhaya
 
PDF
Git real slides
Lucas Couto
 
PDF
Github - Git Training Slides: Foundations
Lee Hanxue
 
PDF
Git and github 101
Senthilkumar Gopal
 
PDF
Git training v10
Skander Hamza
 
PDF
Git - An Introduction
Behzad Altaf
 
PPTX
Git - Basic Crash Course
Nilay Binjola
 
PPTX
Git basics to advance with diagrams
Dilum Navanjana
 
PPTX
Github basics
Radoslav Georgiev
 
KEY
Introduction To Git
Arnaud Seilles
 
KEY
The everyday developer's guide to version control with Git
E Carter
 
PPTX
Git n git hub
Jiwon Baek
 
PPTX
Introduction git
Dian Sigit Prastowo
 
PDF
Git and Github
Wen-Tien Chang
 
PDF
Git basics
GHARSALLAH Mohamed
 
PPTX
Git One Day Training Notes
glen_a_smith
 
PPTX
Github
MeetPatel710
 
PDF
Learning git
Sid Anand
 
PDF
Git Version Control System
KMS Technology
 
Git 101 for Beginners
Anurag Upadhaya
 
Git real slides
Lucas Couto
 
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git and github 101
Senthilkumar Gopal
 
Git training v10
Skander Hamza
 
Git - An Introduction
Behzad Altaf
 
Git - Basic Crash Course
Nilay Binjola
 
Git basics to advance with diagrams
Dilum Navanjana
 
Github basics
Radoslav Georgiev
 
Introduction To Git
Arnaud Seilles
 
The everyday developer's guide to version control with Git
E Carter
 
Git n git hub
Jiwon Baek
 
Introduction git
Dian Sigit Prastowo
 
Git and Github
Wen-Tien Chang
 
Git basics
GHARSALLAH Mohamed
 
Git One Day Training Notes
glen_a_smith
 
Github
MeetPatel710
 
Learning git
Sid Anand
 
Git Version Control System
KMS Technology
 

Similar to GIT | Distributed Version Control System (20)

PPTX
Git.pptx
PalashIMS
 
PPTX
Git and github
Teodora Ahkozidou
 
PDF
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
PPTX
Git overview
Gowarthini
 
PPTX
Git Github GDSC.pptx
TusharChoudhary72015
 
PPTX
Git and Github
Teodora Ahkozidou
 
PPTX
Getting with GIT
Moyinoluwa Adeyemi
 
PPTX
Learning Basic GIT Cmd
srinathcox
 
PDF
Mini git tutorial
Cristian Lucchesi
 
PPTX
Git learning
Amit Gupta
 
PPTX
GIT.pptx
Soumen Debgupta
 
PPTX
Git-guidance for beginner- IT support.pptx.pptx
vietnguyen1989
 
PPTX
Git-guidance for beginner- IT support.pptx
vietnguyen1989
 
PPT
git2.ppt
ssusered2ec2
 
PDF
Github git-cheat-sheet
jaehyok Song
 
PDF
Git 入门与实践
Terry Wang
 
PDF
Git
Terry Wang
 
PDF
Git 入门 与 实践
Terry Wang
 
PPT
Git presentation
James Cuzella
 
PPTX
git github PPT_GDSCIIITK.pptx
AbelPhilipJoseph
 
Git.pptx
PalashIMS
 
Git and github
Teodora Ahkozidou
 
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
Git overview
Gowarthini
 
Git Github GDSC.pptx
TusharChoudhary72015
 
Git and Github
Teodora Ahkozidou
 
Getting with GIT
Moyinoluwa Adeyemi
 
Learning Basic GIT Cmd
srinathcox
 
Mini git tutorial
Cristian Lucchesi
 
Git learning
Amit Gupta
 
GIT.pptx
Soumen Debgupta
 
Git-guidance for beginner- IT support.pptx.pptx
vietnguyen1989
 
Git-guidance for beginner- IT support.pptx
vietnguyen1989
 
git2.ppt
ssusered2ec2
 
Github git-cheat-sheet
jaehyok Song
 
Git 入门与实践
Terry Wang
 
Git 入门 与 实践
Terry Wang
 
Git presentation
James Cuzella
 
git github PPT_GDSCIIITK.pptx
AbelPhilipJoseph
 
Ad

More from Mohammad Imam Hossain (20)

PDF
DS & Algo 6 - Offline Assignment 6
Mohammad Imam Hossain
 
PDF
DS & Algo 6 - Dynamic Programming
Mohammad Imam Hossain
 
PDF
DS & Algo 5 - Disjoint Set and MST
Mohammad Imam Hossain
 
PDF
DS & Algo 4 - Graph and Shortest Path Search
Mohammad Imam Hossain
 
PDF
DS & Algo 3 - Offline Assignment 3
Mohammad Imam Hossain
 
PDF
DS & Algo 3 - Divide and Conquer
Mohammad Imam Hossain
 
PDF
DS & Algo 2 - Offline Assignment 2
Mohammad Imam Hossain
 
PDF
DS & Algo 2 - Recursion
Mohammad Imam Hossain
 
PDF
DS & Algo 1 - Offline Assignment 1
Mohammad Imam Hossain
 
PDF
DS & Algo 1 - C++ and STL Introduction
Mohammad Imam Hossain
 
PDF
DBMS 1 | Introduction to DBMS
Mohammad Imam Hossain
 
PDF
DBMS 10 | Database Transactions
Mohammad Imam Hossain
 
PDF
DBMS 3 | ER Diagram to Relational Schema
Mohammad Imam Hossain
 
PDF
DBMS 2 | Entity Relationship Model
Mohammad Imam Hossain
 
PDF
DBMS 7 | Relational Query Language
Mohammad Imam Hossain
 
PDF
DBMS 4 | MySQL - DDL & DML Commands
Mohammad Imam Hossain
 
PDF
DBMS 5 | MySQL Practice List - HR Schema
Mohammad Imam Hossain
 
PDF
TOC 10 | Turing Machine
Mohammad Imam Hossain
 
PDF
TOC 9 | Pushdown Automata
Mohammad Imam Hossain
 
PDF
TOC 8 | Derivation, Parse Tree & Ambiguity Check
Mohammad Imam Hossain
 
DS & Algo 6 - Offline Assignment 6
Mohammad Imam Hossain
 
DS & Algo 6 - Dynamic Programming
Mohammad Imam Hossain
 
DS & Algo 5 - Disjoint Set and MST
Mohammad Imam Hossain
 
DS & Algo 4 - Graph and Shortest Path Search
Mohammad Imam Hossain
 
DS & Algo 3 - Offline Assignment 3
Mohammad Imam Hossain
 
DS & Algo 3 - Divide and Conquer
Mohammad Imam Hossain
 
DS & Algo 2 - Offline Assignment 2
Mohammad Imam Hossain
 
DS & Algo 2 - Recursion
Mohammad Imam Hossain
 
DS & Algo 1 - Offline Assignment 1
Mohammad Imam Hossain
 
DS & Algo 1 - C++ and STL Introduction
Mohammad Imam Hossain
 
DBMS 1 | Introduction to DBMS
Mohammad Imam Hossain
 
DBMS 10 | Database Transactions
Mohammad Imam Hossain
 
DBMS 3 | ER Diagram to Relational Schema
Mohammad Imam Hossain
 
DBMS 2 | Entity Relationship Model
Mohammad Imam Hossain
 
DBMS 7 | Relational Query Language
Mohammad Imam Hossain
 
DBMS 4 | MySQL - DDL & DML Commands
Mohammad Imam Hossain
 
DBMS 5 | MySQL Practice List - HR Schema
Mohammad Imam Hossain
 
TOC 10 | Turing Machine
Mohammad Imam Hossain
 
TOC 9 | Pushdown Automata
Mohammad Imam Hossain
 
TOC 8 | Derivation, Parse Tree & Ambiguity Check
Mohammad Imam Hossain
 
Ad

Recently uploaded (20)

PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
community health nursing question paper 2.pdf
Prince kumar
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 

GIT | Distributed Version Control System

  • 1. GIT >> Version Control System Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 2. Version Control System - VCS Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. ▸ It allows you to revert selected files back to a previous state, revert the entire project back to a previous state, compare changes over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more. ▸ Using a VCS also generally means that if you screw things up or lose files, you can easily recover. 2 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 3. Local VCS - LVCS 3 Local VCS maintains a simple database that records all the changes to files under revision control. It keeps patch sets (i.e. the difference between files) in a special format on disk; it can then re-create what any file looked like at any point in time by adding up all the patches. Problem >> How to collaborate with other developers? Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 4. Centralized VCS - CVCS Centralized Version Control Systems (CVCSs) have a single server that contains all the versioned files, and a number of clients that check out files from that central place. Problem >> Centralized server is a single point of failure. 4 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 5. Distributed VCS - DVCS In a Distributed Version Control Systems (DVCSs) clients don’t just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. if any server dies, and these systems were collaborating via that server, any of the client repositories can be copied back up to the server to restore it. Every clone is really a full backup of all the data. 5 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 6. DVCS >> GIT ▸ Git is a distributed version-control system for tracking changes in source 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. ▸ It was created by Linux Development Community (in particular, Linus Torvalds) in 2005 for development of the Linux kernel when the relationship between the community and the BitKeeper company broke down. ▸ Git naming: ▹ In British slang, unpleasant person ▹ Global information tracker ▹ Goddamn idiotic truckload of sh*t 6 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 7. GIT ▸ GIT thinks of its data more like a series of snapshots of a miniature filesystem. ▸ With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. ▸ To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored. 7 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 8. GIT >> File States ▸ Each file in the working directory can be in 2 states: ▹ Tracked – files that were in the last snapshot. ▹ Untracked – everything else, not in the last snapshot and not in the staging area. ▸ Tracked file states: ▹ Unmodified/Committed – data is safely stored in the local database. ▹ Modified – you have changed the file but have not committed it to your database yet. ▹ Staged – you have marked a modified file in its current version to go into your next commit snapshot. 8 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 9. GIT >> Stage and Commit Process ▸ Staging the files computes the checksum for each one, stores that version of the file in the Git repository and adds that checksum to the staging area. ▸ During git commit, git checksums each subdirectory and stores them as a tree object in the Git repository. ▸ Git then creates a commit object containing metadata and pointer to the project tree. 9 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 10. GIT >> Multiple Commits Process ▸ The scenario of multiple commits. ▸ Each new commit stores a pointer to the commit that came immediately before it. 10 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 11. 11 GIT Command Line - only place you can run all Git commands Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 12. GIT CLI >> First-time Setup 12 ▸ Version check: $ git --version ▸ Configuration scope: ▹ --system : values applied to every user on the system and all their repositories. ▹ --global : values specific personally to you and affects all the repositories you work with. ▹ --local : values specific to that single repository you are currently using. ▸ Get/Set Configuration variables : ▹ To view all the settings: $ git config --list ▹ To view all the settings with file path: $ git config --list --show-origin ▹ To check a specific variable value: $ git config <key> ▹ To set a specific variable value: $ git config --global <key> <value> ▸ First time setup: $ git config --global user.name “username” $ git config -- global user.email “[email protected]” cause every git commit uses your name and email ▸ Getting help: $ git <verb> --help Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 13. GIT CLI >> Getting a GIT Repository 13 ▸ Initialize an existing local directory: Go within that directory and run - $ git init ▸ Clone an existing remote repository: To clone the remote repository run - $ git clone <url> To clone the remote repository into your directory run - $ git clone <url> <new-directory-name> Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 14. GIT CLI >> Creating a GIT Repository 14 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 15. GIT CLI >> Check/Add/Remove Remote Repository 15 ▸ To show all the remote repositories you have configured $ git remote –v ▸ To add new remote repositories $ git remote add <shortname> <url> git clone command implicitly adds the remote for you ▸ To remove remote repository $ git remote remove <shortname> ▸ To rename remote repository $ git remote rename <old-shortname> <new-shortname> Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 16. GIT CLI >> Fetch/Pull/Push Information 16 ▸ To fetch $ git fetch <remote> This command only downloads the data to your local repository - it doesn’t automatically merge it. ▸ To pull $ git pull <remote> <branch> If your current branch(master) is set up to track a remote branch(remote master), then this command automatically fetch and then merge that remote branch into your current branch. ▸ To push (pull/fetch before push) $ git push <remote> <branch> ▸ Inspecting a remote, $ git remote show <remote> Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 17. GIT CLI >> How git fetch Works 17 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 18. GIT CLI >> How git fetch Works 18 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 19. GIT CLI >> Recording Repository Changes 19 ▸ To get the status of the files $ git status ▸ To track new file/stage a file $ git add <file-path> To add changes from all the tracked and untracked files $ git add -A ▸ To commit your staged changes (commit records the snapshot you set up in your staging area) $ git commit –m <commit-message> To skip the staging area and commit every tracked files(auto staged) $ git commit –a –m <commit-message> Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 20. GIT CLI >> Ignoring Specific Files 20 ▸ Create a file named .gitignore and list the file names/patterns that you don’t want GIT to automatically add/even show you as being untracked. For example, Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU *.[oa] to ignore any files ending with .o or, .a !lib.a to track lib.a file even though you are ignoring .a files /TODO to ignore TODO file in the current directory, not subdirectory build/ to ignore all files in any directory named build doc/*.txt to ignore doc/notes.txt file, bit not doc/server/arch.txt, i.e. not within subdirectory doc/**/*.pdf To ignore all .pdf files in the doc/ directory and its subdirectory
  • 21. GIT CLI >> Viewing the Changes 21 ▸ To see what you’ve changed but not yet staged (diff. between staged and modified files) $ git diff ▸ To see what you’ve staged that will go into the next commit (diff. between staged and committed files) $ git diff --cached ▸ To rename a file in GIT $ git mv <file_from> <file_to> ▸ To make a tracked file untracked $ git rm --cached <file-name> To remove a file from your working directory $ git rm <file-name> Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 22. GIT CLI >> Commit History 22 ▸ To list all the commits made in the repository in reverse chronological order, $ git log ▸ To see some abbreviated stats for each commit $ git log --stat ▸ To see the last 3 commit history $ git log -3 ▸ To see the difference introduced in each commit, $ git log -p -2 ▸ To show each commit in one line $ git log --oneline ▸ To see the branch and graph history in the form of a graph $ git log --pretty=format:”%h %s” --graph Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 23. GIT CLI >> git log Options 23 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU -<n> Show only the last n commits --since, --after Limit commits to those made after the specified date --until, --before Limit the commits to those made before the specified date --author Only show commits in which the author entry matches the specified string --committer Only show commits in which the committer entry matches the specified string --grep Only show commits with a commit message containing the string -S Only show commits adding or removing code matching the string
  • 24. GIT CLI >> git log Options 24 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU -p Show the patch introduced in each commit --stat Show statistics for files modified in each commit --pretty Show commits in an alternate format. Oneline/short/full/fuller/format --oneline Shorthand for --pretty=oneline --abbrev-commit --graph Display an ASCII graph of the branch and merge history beside the log output %H Commit hash %an, %ae, %ad Author name, email and date %h Abbreviated commit hash %cn, %ce, %cd Committer name, email and date %P Parent hashes %s Subject %p Abbreviated parent hashes
  • 25. GIT CLI >> Undoing Things 25 ▸ To redo the last commit $ git commit --amend -m “new commit message” or $ git commit –amend ▸ To unstage a staged file $ git reset HEAD <file-name> ▸ To unmodify a modified file $ git checkout -- <file-name> Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 26. GIT CLI >> Branching 26 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU ▸ To list all the current branches $ git branch The * pointed branch indicates the branch currently HEAD points to ▸ To get the list of merged branches $ git branch –merged ▸ To get the list of unmerged branches $ git branch –no-merged ▸ To create a new branch $ git branch <branch-name> ▸ To switch to new branch $ git checkout <branch-name> ▸ To remove an already merged branch $ git branch –d <branch-name> ▸ To remove an unmerged branch $ git branch –D <branch-name>
  • 27. GIT CLI >> Branching >> initial local repository 27 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 28. GIT CLI >> Branching >> creating a new branch 28 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU $ git branch <branch-name>
  • 29. GIT CLI >> Branching >> switching to a new branch 29 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU $ git checkout <branch-name>
  • 30. GIT CLI >> Branching >> staging & committing in the new branch 30 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU $ git commit –a –m “commit message”
  • 31. GIT CLI >> Branching >> switching back to master branch 31 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU $ git checkout master
  • 32. GIT CLI >> Branching >> staging and committing in master branch 32 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU $ git commit –a –m “commit message”
  • 33. GIT CLI >> Branching >> example-step 1 33 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 34. GIT CLI >> Branching >> example-step 2 34 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU Creating a new branch and switching to that branch $ git checkout -b iss53 or, $ git branch iss53 $ git checkout iss53
  • 35. GIT CLI >> Branching >> example-step 3 35 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU Committing in that new branch $ git commit -a –m “commit message”
  • 36. GIT CLI >> Branching >> example-step 4 36 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU Switching back to master, creating new branch hotfix, switching to that branch and performing a new commit there $ git checkout master $ git checkout hotfix $ git branch hotfix $ git commit -a –m “commit message”
  • 37. GIT CLI >> Branching >> example-step 5 37 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU Switching back to branch master and merging with the hotfix branch $ git checkout master $ git merge hotfix
  • 38. GIT CLI >> Branching >> example-step 6 38 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU Deleting the hotfix branch, switching to iss53 branch and performing new commit there $ git branch -d hotfix $ git checkout iss53 $ git commit –a –m “commit message”
  • 39. GIT CLI >> Branching >> example-step 7 39 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU Going back to master branch $ git checkout master
  • 40. GIT CLI >> Branching >> example-step 8 40 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU Merging the master branch with iss53 branch $ git merge iss53 If conflict occurs, then open and edit the conflicted file remove the <<<<<<<, =======, >>>>>>> symbols, perform necessary changes, finally stage and commit the changes
  • 41. GIT CLI >> Revision Selection 41 ▸ To show the details of a specific commit $ git show <SHA-1 hash value of that commit> ▸ To see the log of where your HEAD and branch references have been for the last few months $ git reflog ▸ To refer to the older commits from the current HEAD position $ git show HEAD@{5} ▸ To show the first parent of a specific commit $ git show HEAD^ To show the second parent(meaning other branch parent) of a specific commit $ git show HEAD^2 ▸ To show the first parent of a first parent $ git show HEAD~2 ▸ Difference between the second branch commits with first branch commits $ git log br1..br2 ▸ Difference between both of the branch commits $ git log br1…br2 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 42. GIT CLI >>Temporarily saving changes at a Branch 42 To switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command. Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).  To save the current work $ git stash push  To check all the stashes $git stash list  To apply any certain stash changes to the current branch file $ git stash apply or, $ git stash apply stash@{2}  To delete a saved stash from the stack $ git stash drop stash@{1}  To apply the stash changes and also delete from the stack at the same time $ git stash pop stash@{1} Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 43. GIT CLI >>The Role of Reset 43 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 44. GIT CLI >>The Role of Reset 44 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 45. GIT CLI >>The Role of Reset 45 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 46. GIT CLI >>The Role of Reset 46 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 47. GIT CLI >>The Role of Reset 47 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 48. GIT CLI >>The Role of Reset 48 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 49. GIT CLI >>The Role of Reset 49 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 50. GIT CLI >>The Role of Reset 50 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 51. GIT CLI >>The Role of Reset 51 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU
  • 52. GIT CLI >>The Role of Reset 52 Mohammad Imam Hossain | Lecturer, dept. of CSE | UIU