SlideShare a Scribd company logo
Git tutorial
 What is GIT?
 Cloning a remote repository
 Creating a repository
 Git config
 Adding remote repository
 GIT trees
 Committing to local repo and pushing commits to remote repo
 Pulling code from remote repo
 Switching working directory to a past commit
 Undoing changes(erasing local commits)
 Merging and Conflict Resolution
 GIT DiffTool and MergeTool
 Git Panoramic View
 Stashing
 Reverting remote repo to previous commit
 GIT-o-LOGY
 Ten Command(ments)
 PUSH/PULL WORKFLOW
 Common Use-Cases
 Git related software
 It is a Distributed Version Control System.
 Developed by Linux Torvalds (Founder of Linux).
 Each developer machine has his/her own local repository to which code can be
committed.
 Code can be committed without an internet connection as repository is local.
 Code commits in local repository can be pushed to remote repository which could
be shared with other developers.
 We could sync our repository with multiple repositories.
 Merging and Branching is seamless.
 It copies the contents from a remote repository to a local repository.
 Navigate to any folder on your file system using GIT CMD.
 Run the following command.
> git clone http://USTR-ERL-5966.na.uis.unisys.com/USFN/git-playground.git
 It essentially copies two folder hierarchies
 .git folder
 project content
 All the git commands work on the “.git” folder. A folder turns into a repository if it
contains “.git” folder.
 All the GIT commands can run only in the folder containing “.git” folder.
 To create a repository on your local system.
 All you have to do is run the following command in the folder where you want
your repository to be created.
> git init
 When you run git init and .git folder is created which indicates that a repository
has been created.
 git init is all you need to put a folder’s content in version control. We are good to
commit code to our local repository now.
 Global Settings
 > git config --global user.name “Gitty Kumar“
 > git config --global user.name “gitkum@gmail.com“
 Project settings
 > git config user.name “Gitty“
 > git config user.email Gitty@gmail.com
 Storing credentials so that we don’t have to type often. Note that password is stored
as plain text in .gitcredentials file.
 > git config –global credential.helper store
 The .gitconfig file is located in .git folder in each local repository and also in the user’s
home directory.
 Generally, when we clone from a particular repository the “origin” alias is set
automatically
> git remote add origin http://IP/path/to/repository
 Also, if we want to change the origin URL, we could do so by the following
command
> git remote set-url origin origin http://IP/path/to/repository
 Working Directory: It holds the actual files which we would be working on. It is
the area where we would be making modifications to the files.
 Staging/Index: It is the staging area which snapshot is prepared. Note that it is a
single file.
 Repository: Maintains a series of committed snapshots.
 GIT follows a two stage commit process.
 First we need to execute git “add” which adds the changes to the staging/index.
> git add . (Add all the files in the current directory to the staging/index area)
 Next we need to execute git “commit” which adds the staged changes to the repository
> git commit –m “Implemented a new feature” (Commits the changes in staging area
to the repository)
 Next we need to push our commits to remote repository by issuing the following
command. Note that origin is an alias for the URL which is stored in .gitconfig and
master is the name of the branch to which we want to push our changes.
> git push origin master
Note: Typically pushing code into repository might not be straight forward and we might
have to follow the push/pull workflow flowchart mentioned in the later slides.
 We have to first fetch the code from the remote repository by issuing the following
command. It gets the code from remote repository but does not affect with our working
directory. It is like a preview of changes which have taken place in remote repository.
> git fetch origin master
 Then run the following command
> git status
 If it says that the branch and origin/master have diverged, it means that we have
different commits in local and remote repository. We need to run the following
command to re-apply our commits on top of the remote commits.
> git rebase origin/master
 If at all, we have no committed changes, then we could use the following command. It
is a called a fast forward merge and no additional commit will be created.
> git merge origin master
Note: Please don’t use “git pull origin master”
 Revert a working directory to a past commit.
> git checkout 1asd9rrtretero
It affects the working directory. It is useful when we want to see build the application from the
code on a past commit. Whenever the above command is run it will put HEAD in a detached
state. When head is in detached state, we should not do any commits. After we check that the
code on a particular commit we can again take the head to a stable state by the following
command.
>git checkout master
 Used to navigate between branches.
> git checkout feature-2
Assuming if there is another branch by name “feature-2”. It affects the working directory. When
we checkout a branch three things happen.
 The HEAD points to the branch’s latest commit.
 Populates the staging/index with the snapshot of the commit.
 Checks out the contents of the file in the staging/index area to the working directory
HEAD is said to be in detached state if it is not pointing to any of the
branches(Ex:master)
 Erases history of commits from the local repository and resets repository to the commit
mentioned in the command. Resets the staging area to the repository. It affects only
the staging area and repository.
> git reset 123asfasdf32434
 Same as the above command but it changes the files in the working directory. After
this command the working directory, staging and repository are in sync
> git reset --hard12sresfasdfs343
 Resetting your working directory to the remote repository’s latest commit. The below is
useful when you have done some wrong changes and want to go back to the remote
repository’s state.
> git reset --hard origin/master
Be cautious when you use reset –hard as your local changes will be overridden.
Never try to run reset –hard on public commits(commits which are pushed to remote repository)
as it might affect other developers and cause confusion.
 What is a merge conflict and when does it happen?
 Whenever there is a difference of commits between our local repo branch and the remote
repository branch there is said to be a merge conflict when we pull code from remote
repository(a.k.a. Upstream.).
For instance
Remote repo might have the following commits (a<-b<-c<-d) “c” being the latest commit
Our local repo might have the following commits (a<-b<-e<-f) with “f” being the latest.
When
At this point when we issue “git pull” there is a merge conflict so git will try to resolve
conflicts automatically but sometimes manually intervention is required in case if the
same file was modified in “c” and “e” commit.
The below command gets the latest changesets from the remote repository and merges
them with code in the working directory. If merging is successful this command executes
successfully else we have to manually merge.
> git pull origin master
 The following are needed to configure the diff tool and mergetool. We would be
using “Meld”.
> git config --global diff.tool meld
> git config --global merge.tool meld
 Ensure that the following lines are added to the .gitconfig of your respective user
directory.
[mergetool "meld"]
cmd = "C:Program Files (x86)MeldMeld.exe" $LOCAL $MERGED
$REMOTE
[difftool "meld"]
cmd = "C:Program Files (x86)MeldMeld.exe" $REMOTE $LOCAL
Git tutorial
 In fact, most of the times, we might have some uncommitted changes and when we try
to issue a “git pull” it fails to do so because of the following error.
“Your local changes to the following files would be overwritten by merge: Please commit or stash them”
At this stage, we might not be interested to commit as we might have not completed
the feature. Instead, we could “stash” which means temporarily saving your work in a
separate place.
Just execute the following command
> git stash
After this you could run
> git pull
Which will execute successfully. Now you must be wondering how to get back those
uncommitted changes. Just issue the below command which will get the uncommitted
changes back to the working directory.
> git stash pop
 The word “revert” has a different meaning in GIT. Let us say we have a series of
commits with “E” being the latest
A<-B<-C<-D<-E<-F
Revert means undoing the changes made by a specific commit. So, if we issue
> git revert D
Whatever changes made by D will be undone. Please note that it does not mean
that the code will be reverted to the D commit.
 HEAD: Generally, HEAD should point to a branch. It can also point to a commit but
then it is called a detached HEAD.
 Branch: It is a pointer to the latest commit. Every GIT repository has a default branch
called “master”.
 Each of the branches are also called as head but uppercase “HEAD” refers to the
current branch.
 Commit: It is a snapshot of the entire repository at the point of commit.
 GIT Trees: There are three trees namely Working Directory, Staging/Index Area and
the Local repository.
 git clone : Used to clone a remote repository
 git add: Used to add files to the staging area.
 git commit: Commits the changes present in the staging area to the local repository.
 git checkout: Used to switch between branches,
 git reset: Erase commits.
 git push: Pushes code commits from local repository to remote repository.
 git pull: Pulls code commits from remote repository to local repository and then
merges code. So the changes are reflected in the working directory. So
PULL=FETCH+MERGE
 git fetch: Pulls code commits from remote to local repository.
 git merge: Merges code from local repository to working directory.
 git revert: Undoes a commit by adding a new commit.
 git stash: Temporarily storing your uncommitted changes
git add .
(Adds the modified files to the staging/index
area)
git commit –m”Message”
(Commits the changes to the local repository)
git push origin master
(Pushes the commit from local repository to the remote
repository’s(origin) “master” branch )
Is Push
successful??
No (Because remote repository
contains changes which we don’t
have)
git fetch origin master
(Fetching commits from remote repository to local repository)
Is rebase
successful??
git rebase origin/master
(It replays your commits on top of remote commits, thereby
maintaining a linear history.)
No(because of
conflicts)
git stash
( Stores your uncommitted changes safely so that
they are not disturbed by rebase/merging)
No (Working directory contains
uncommitted changes)
No (Nothing to rebase)
git merge origin/master
(Merges the changes)
Is merge
successful??
Yes
No
Resolve conflicts manually
Yes
Breathe a sigh of relief…
We are done…
No (Because of merge
conflicts)
Did you execute
git stash before
Yes
git stash pop
( Get the uncommitted changes back to working
directory)
YesNo
Start
 Ensuring that local working directory exactly resembles the remote repository.
Note that your local commits/uncommitted changes will be lost.
> git fetch origin master
> git reset –hard origin/master
 Reverting changes to a particular commit in remote repository. Let us say we have
the following sequence of commits
A<-B<-C<-D<-E with D being the latest commit
Now if we want to take the code to a version B that means we need to undo C,D,E
> git revert C D E
> git push origin master
 GIT supports both CLI (Command Line Interface) namely
 GIT CMD
 and GUI (Graphical User Interface) open source clients namely
 GIT GUI
 Atlassian Source Control
 GIT downloads (contains default CLI and GUI):
 https://git-scm.com/download/win
 Eclipse has a plugin name E-git for issuing git commands within eclipse
 http://www.vogella.com/tutorials/EclipseGit/article.html
 Diff and Merge Tool
 https://download.gnome.org/binaries/win32/meld/3.14/Meld-3.14.0-win32.msi (for
windows)
Ad

More Related Content

What's hot (19)

Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2
Biju Thomas
 
Koha installation BALID
Koha installation BALIDKoha installation BALID
Koha installation BALID
Nur Ahammad
 
Spotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairsSpotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairs
DataStax Academy
 
Deployment with Fabric
Deployment with FabricDeployment with Fabric
Deployment with Fabric
andymccurdy
 
Discovering OpenBSD on AWS
Discovering OpenBSD on AWSDiscovering OpenBSD on AWS
Discovering OpenBSD on AWS
Laurent Bernaille
 
NWRUG July 2009 - Darcs
NWRUG July 2009 - DarcsNWRUG July 2009 - Darcs
NWRUG July 2009 - Darcs
PatchSpace Ltd
 
Stacki: Remove Commands
Stacki: Remove CommandsStacki: Remove Commands
Stacki: Remove Commands
StackIQ
 
R hive tutorial - udf, udaf, udtf functions
R hive tutorial - udf, udaf, udtf functionsR hive tutorial - udf, udaf, udtf functions
R hive tutorial - udf, udaf, udtf functions
Aiden Seonghak Hong
 
Linux day 3ppt
Linux day 3pptLinux day 3ppt
Linux day 3ppt
Kalkey
 
Athenticated smaba server config with open vpn
Athenticated smaba server  config with open vpnAthenticated smaba server  config with open vpn
Athenticated smaba server config with open vpn
Chanaka Lasantha
 
Deeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay NetworksDeeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay Networks
Laurent Bernaille
 
Deep Dive in Docker Overlay Networks
Deep Dive in Docker Overlay NetworksDeep Dive in Docker Overlay Networks
Deep Dive in Docker Overlay Networks
Laurent Bernaille
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
Teja Bheemanapally
 
Linea de comandos bioface zem800
Linea de comandos bioface zem800Linea de comandos bioface zem800
Linea de comandos bioface zem800
thomaswarnerherrera
 
vBACD - Introduction to Opscode Chef - 2/29
vBACD - Introduction to Opscode Chef - 2/29vBACD - Introduction to Opscode Chef - 2/29
vBACD - Introduction to Opscode Chef - 2/29
CloudStack - Open Source Cloud Computing Project
 
2009 Itc Nslookup Rev01
2009 Itc Nslookup Rev012009 Itc Nslookup Rev01
2009 Itc Nslookup Rev01
JayMNEA
 
Perl in RPM-Land
Perl in RPM-LandPerl in RPM-Land
Perl in RPM-Land
Dave Cross
 
Quick and Dirty Python Deployments with Heroku
Quick and Dirty Python Deployments with HerokuQuick and Dirty Python Deployments with Heroku
Quick and Dirty Python Deployments with Heroku
Daniel Pritchett
 
Dns explained
Dns explainedDns explained
Dns explained
Lucas Girardin
 
Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2Install and upgrade Oracle grid infrastructure 12.1.0.2
Install and upgrade Oracle grid infrastructure 12.1.0.2
Biju Thomas
 
Koha installation BALID
Koha installation BALIDKoha installation BALID
Koha installation BALID
Nur Ahammad
 
Spotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairsSpotify: Automating Cassandra repairs
Spotify: Automating Cassandra repairs
DataStax Academy
 
Deployment with Fabric
Deployment with FabricDeployment with Fabric
Deployment with Fabric
andymccurdy
 
NWRUG July 2009 - Darcs
NWRUG July 2009 - DarcsNWRUG July 2009 - Darcs
NWRUG July 2009 - Darcs
PatchSpace Ltd
 
Stacki: Remove Commands
Stacki: Remove CommandsStacki: Remove Commands
Stacki: Remove Commands
StackIQ
 
R hive tutorial - udf, udaf, udtf functions
R hive tutorial - udf, udaf, udtf functionsR hive tutorial - udf, udaf, udtf functions
R hive tutorial - udf, udaf, udtf functions
Aiden Seonghak Hong
 
Linux day 3ppt
Linux day 3pptLinux day 3ppt
Linux day 3ppt
Kalkey
 
Athenticated smaba server config with open vpn
Athenticated smaba server  config with open vpnAthenticated smaba server  config with open vpn
Athenticated smaba server config with open vpn
Chanaka Lasantha
 
Deeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay NetworksDeeper dive in Docker Overlay Networks
Deeper dive in Docker Overlay Networks
Laurent Bernaille
 
Deep Dive in Docker Overlay Networks
Deep Dive in Docker Overlay NetworksDeep Dive in Docker Overlay Networks
Deep Dive in Docker Overlay Networks
Laurent Bernaille
 
Linea de comandos bioface zem800
Linea de comandos bioface zem800Linea de comandos bioface zem800
Linea de comandos bioface zem800
thomaswarnerherrera
 
2009 Itc Nslookup Rev01
2009 Itc Nslookup Rev012009 Itc Nslookup Rev01
2009 Itc Nslookup Rev01
JayMNEA
 
Perl in RPM-Land
Perl in RPM-LandPerl in RPM-Land
Perl in RPM-Land
Dave Cross
 
Quick and Dirty Python Deployments with Heroku
Quick and Dirty Python Deployments with HerokuQuick and Dirty Python Deployments with Heroku
Quick and Dirty Python Deployments with Heroku
Daniel Pritchett
 

Similar to Git tutorial (20)

Git training
Git trainingGit training
Git training
eric7master
 
Git learning
Git learningGit learning
Git learning
Amit Gupta
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
Git github
Git githubGit github
Git github
Anurag Deb
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
9 series
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with Git
Rasan Samarasinghe
 
git github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptx
AbelPhilipJoseph
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
alignan
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
Senthilkumar Gopal
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
Sothearin Ren
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
Susan Tan
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
DSC GVP
 
Git commands
Git commandsGit commands
Git commands
Viyaan Jhiingade
 
Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
PravallikaTammisetty
 
Git basics
Git basicsGit basics
Git basics
GHARSALLAH Mohamed
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
Abdul Basit
 
Git introduction
Git introductionGit introduction
Git introduction
satyendrajaladi
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
Jesús Miguel Benito Calzada
 
Lets Git Together
Lets Git TogetherLets Git Together
Lets Git Together
Rakesh Jha
 
Git cheat-sheet 2021
Git cheat-sheet 2021Git cheat-sheet 2021
Git cheat-sheet 2021
Rana Faisal Haroon
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
9 series
 
Advanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with GitAdvanced Web Development in PHP - Code Versioning and Branching with Git
Advanced Web Development in PHP - Code Versioning and Branching with Git
Rasan Samarasinghe
 
git github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptx
AbelPhilipJoseph
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
alignan
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
Sothearin Ren
 
How to Really Get Git
How to Really Get GitHow to Really Get Git
How to Really Get Git
Susan Tan
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
DSC GVP
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
Abdul Basit
 
Lets Git Together
Lets Git TogetherLets Git Together
Lets Git Together
Rakesh Jha
 
Ad

Recently uploaded (20)

Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Ad

Git tutorial

  • 2.  What is GIT?  Cloning a remote repository  Creating a repository  Git config  Adding remote repository  GIT trees  Committing to local repo and pushing commits to remote repo  Pulling code from remote repo  Switching working directory to a past commit  Undoing changes(erasing local commits)  Merging and Conflict Resolution  GIT DiffTool and MergeTool  Git Panoramic View  Stashing  Reverting remote repo to previous commit  GIT-o-LOGY  Ten Command(ments)  PUSH/PULL WORKFLOW  Common Use-Cases  Git related software
  • 3.  It is a Distributed Version Control System.  Developed by Linux Torvalds (Founder of Linux).  Each developer machine has his/her own local repository to which code can be committed.  Code can be committed without an internet connection as repository is local.  Code commits in local repository can be pushed to remote repository which could be shared with other developers.  We could sync our repository with multiple repositories.  Merging and Branching is seamless.
  • 4.  It copies the contents from a remote repository to a local repository.  Navigate to any folder on your file system using GIT CMD.  Run the following command. > git clone http://USTR-ERL-5966.na.uis.unisys.com/USFN/git-playground.git  It essentially copies two folder hierarchies  .git folder  project content  All the git commands work on the “.git” folder. A folder turns into a repository if it contains “.git” folder.  All the GIT commands can run only in the folder containing “.git” folder.
  • 5.  To create a repository on your local system.  All you have to do is run the following command in the folder where you want your repository to be created. > git init  When you run git init and .git folder is created which indicates that a repository has been created.  git init is all you need to put a folder’s content in version control. We are good to commit code to our local repository now.
  • 6.  Global Settings  > git config --global user.name “Gitty Kumar“  > git config --global user.name “[email protected]“  Project settings  > git config user.name “Gitty“  > git config user.email [email protected]  Storing credentials so that we don’t have to type often. Note that password is stored as plain text in .gitcredentials file.  > git config –global credential.helper store  The .gitconfig file is located in .git folder in each local repository and also in the user’s home directory.
  • 7.  Generally, when we clone from a particular repository the “origin” alias is set automatically > git remote add origin http://IP/path/to/repository  Also, if we want to change the origin URL, we could do so by the following command > git remote set-url origin origin http://IP/path/to/repository
  • 8.  Working Directory: It holds the actual files which we would be working on. It is the area where we would be making modifications to the files.  Staging/Index: It is the staging area which snapshot is prepared. Note that it is a single file.  Repository: Maintains a series of committed snapshots.
  • 9.  GIT follows a two stage commit process.  First we need to execute git “add” which adds the changes to the staging/index. > git add . (Add all the files in the current directory to the staging/index area)  Next we need to execute git “commit” which adds the staged changes to the repository > git commit –m “Implemented a new feature” (Commits the changes in staging area to the repository)  Next we need to push our commits to remote repository by issuing the following command. Note that origin is an alias for the URL which is stored in .gitconfig and master is the name of the branch to which we want to push our changes. > git push origin master Note: Typically pushing code into repository might not be straight forward and we might have to follow the push/pull workflow flowchart mentioned in the later slides.
  • 10.  We have to first fetch the code from the remote repository by issuing the following command. It gets the code from remote repository but does not affect with our working directory. It is like a preview of changes which have taken place in remote repository. > git fetch origin master  Then run the following command > git status  If it says that the branch and origin/master have diverged, it means that we have different commits in local and remote repository. We need to run the following command to re-apply our commits on top of the remote commits. > git rebase origin/master  If at all, we have no committed changes, then we could use the following command. It is a called a fast forward merge and no additional commit will be created. > git merge origin master Note: Please don’t use “git pull origin master”
  • 11.  Revert a working directory to a past commit. > git checkout 1asd9rrtretero It affects the working directory. It is useful when we want to see build the application from the code on a past commit. Whenever the above command is run it will put HEAD in a detached state. When head is in detached state, we should not do any commits. After we check that the code on a particular commit we can again take the head to a stable state by the following command. >git checkout master  Used to navigate between branches. > git checkout feature-2 Assuming if there is another branch by name “feature-2”. It affects the working directory. When we checkout a branch three things happen.  The HEAD points to the branch’s latest commit.  Populates the staging/index with the snapshot of the commit.  Checks out the contents of the file in the staging/index area to the working directory HEAD is said to be in detached state if it is not pointing to any of the branches(Ex:master)
  • 12.  Erases history of commits from the local repository and resets repository to the commit mentioned in the command. Resets the staging area to the repository. It affects only the staging area and repository. > git reset 123asfasdf32434  Same as the above command but it changes the files in the working directory. After this command the working directory, staging and repository are in sync > git reset --hard12sresfasdfs343  Resetting your working directory to the remote repository’s latest commit. The below is useful when you have done some wrong changes and want to go back to the remote repository’s state. > git reset --hard origin/master Be cautious when you use reset –hard as your local changes will be overridden. Never try to run reset –hard on public commits(commits which are pushed to remote repository) as it might affect other developers and cause confusion.
  • 13.  What is a merge conflict and when does it happen?  Whenever there is a difference of commits between our local repo branch and the remote repository branch there is said to be a merge conflict when we pull code from remote repository(a.k.a. Upstream.). For instance Remote repo might have the following commits (a<-b<-c<-d) “c” being the latest commit Our local repo might have the following commits (a<-b<-e<-f) with “f” being the latest. When At this point when we issue “git pull” there is a merge conflict so git will try to resolve conflicts automatically but sometimes manually intervention is required in case if the same file was modified in “c” and “e” commit. The below command gets the latest changesets from the remote repository and merges them with code in the working directory. If merging is successful this command executes successfully else we have to manually merge. > git pull origin master
  • 14.  The following are needed to configure the diff tool and mergetool. We would be using “Meld”. > git config --global diff.tool meld > git config --global merge.tool meld  Ensure that the following lines are added to the .gitconfig of your respective user directory. [mergetool "meld"] cmd = "C:Program Files (x86)MeldMeld.exe" $LOCAL $MERGED $REMOTE [difftool "meld"] cmd = "C:Program Files (x86)MeldMeld.exe" $REMOTE $LOCAL
  • 16.  In fact, most of the times, we might have some uncommitted changes and when we try to issue a “git pull” it fails to do so because of the following error. “Your local changes to the following files would be overwritten by merge: Please commit or stash them” At this stage, we might not be interested to commit as we might have not completed the feature. Instead, we could “stash” which means temporarily saving your work in a separate place. Just execute the following command > git stash After this you could run > git pull Which will execute successfully. Now you must be wondering how to get back those uncommitted changes. Just issue the below command which will get the uncommitted changes back to the working directory. > git stash pop
  • 17.  The word “revert” has a different meaning in GIT. Let us say we have a series of commits with “E” being the latest A<-B<-C<-D<-E<-F Revert means undoing the changes made by a specific commit. So, if we issue > git revert D Whatever changes made by D will be undone. Please note that it does not mean that the code will be reverted to the D commit.
  • 18.  HEAD: Generally, HEAD should point to a branch. It can also point to a commit but then it is called a detached HEAD.  Branch: It is a pointer to the latest commit. Every GIT repository has a default branch called “master”.  Each of the branches are also called as head but uppercase “HEAD” refers to the current branch.  Commit: It is a snapshot of the entire repository at the point of commit.  GIT Trees: There are three trees namely Working Directory, Staging/Index Area and the Local repository.
  • 19.  git clone : Used to clone a remote repository  git add: Used to add files to the staging area.  git commit: Commits the changes present in the staging area to the local repository.  git checkout: Used to switch between branches,  git reset: Erase commits.  git push: Pushes code commits from local repository to remote repository.  git pull: Pulls code commits from remote repository to local repository and then merges code. So the changes are reflected in the working directory. So PULL=FETCH+MERGE  git fetch: Pulls code commits from remote to local repository.  git merge: Merges code from local repository to working directory.  git revert: Undoes a commit by adding a new commit.  git stash: Temporarily storing your uncommitted changes
  • 20. git add . (Adds the modified files to the staging/index area) git commit –m”Message” (Commits the changes to the local repository) git push origin master (Pushes the commit from local repository to the remote repository’s(origin) “master” branch ) Is Push successful?? No (Because remote repository contains changes which we don’t have) git fetch origin master (Fetching commits from remote repository to local repository) Is rebase successful?? git rebase origin/master (It replays your commits on top of remote commits, thereby maintaining a linear history.) No(because of conflicts) git stash ( Stores your uncommitted changes safely so that they are not disturbed by rebase/merging) No (Working directory contains uncommitted changes) No (Nothing to rebase) git merge origin/master (Merges the changes) Is merge successful?? Yes No Resolve conflicts manually Yes Breathe a sigh of relief… We are done… No (Because of merge conflicts) Did you execute git stash before Yes git stash pop ( Get the uncommitted changes back to working directory) YesNo Start
  • 21.  Ensuring that local working directory exactly resembles the remote repository. Note that your local commits/uncommitted changes will be lost. > git fetch origin master > git reset –hard origin/master  Reverting changes to a particular commit in remote repository. Let us say we have the following sequence of commits A<-B<-C<-D<-E with D being the latest commit Now if we want to take the code to a version B that means we need to undo C,D,E > git revert C D E > git push origin master
  • 22.  GIT supports both CLI (Command Line Interface) namely  GIT CMD  and GUI (Graphical User Interface) open source clients namely  GIT GUI  Atlassian Source Control  GIT downloads (contains default CLI and GUI):  https://git-scm.com/download/win  Eclipse has a plugin name E-git for issuing git commands within eclipse  http://www.vogella.com/tutorials/EclipseGit/article.html  Diff and Merge Tool  https://download.gnome.org/binaries/win32/meld/3.14/Meld-3.14.0-win32.msi (for windows)