SlideShare une entreprise Scribd logo
1  sur  37
GIT: A BRIEF INTRODUCTION
Eng. Amjad Mahfoud
amjadoof@gmail.com
8 - Nov - 2018
1
Slides Structure
Introduction
What is GIT
Using Git
Basic Git commands
Further Reading
2
Introduction
General Prenciples
3
What is Git?
• Git is a distributed version control system for managing source code.
• Ok, so what is version control?
• Simply put, version control is a system for tracking changes to files.
• As you modify files, the version control system records and saves each
change.
• This allows you to restore a previous version of your code at any time.
Eng. Amjad Mahfoud 4amjadoof@gmail.com
What is Git?
• Without a version control system, you are stuck manually saving
multiple versions of your file using different dates and/or names (e.g.
12-02-2016-monkey_code.php; 12-03-2016-monkey_code.php).
• This method is time-consuming and impractical when you are dealing
with hundreds of files.
Eng. Amjad Mahfoud 5amjadoof@gmail.com
What is Git?
• Renaming a file also doesn't give you any context as to what changes
were made or who they were made by.
• When multiple team members edit the same file, overwriting may
occur and it becomes difficult to keep up with the latest file version.
• With Git, you can easily follow your source code's revision history and
track changes.
• You can also go back in time to learn about how the version has
changed and who has made the changes.
• When the latest version of a file is on a shared repository, Git will
prevent unintentional overwrites by anyone on your team who has an
older version of the file.
Eng. Amjad Mahfoud 6amjadoof@gmail.com
Git makes it easy to:
• Keep track of code history
• Collaborate on code as a team
• See who made which changes
• Deploy to staging or production
Eng. Amjad Mahfoud 7amjadoof@gmail.com
Git workflow
• There are three main components of a Git project:
• Repository
• Working tree
• Index
Eng. Amjad Mahfoud amjadoof@gmail.com 8
The repository:
or repo, is the “container” that tracks the changes to your project files.
It holds all the commits—a snapshot of all your files at a point in time—
that have been made. You can access the commit history with the Git
log.
Eng. Amjad Mahfoud amjadoof@gmail.com 9
The working tree
or working directory, consists of files that you are currently working on.
You can think of a working tree as a file system where you can view and
modify files.
Eng. Amjad Mahfoud amjadoof@gmail.com 10
The index
or staging area, is where commits are prepared. The index compares the
files in the working tree to the files in the repo. When you make a
change in the working tree, the index marks the file as modified before
it is committed.
Eng. Amjad Mahfoud amjadoof@gmail.com 11
The three main components of a Git project:
the repository, index, and working tree.
Eng. Amjad Mahfoud amjadoof@gmail.com 12
The basic Git workflow:
• Modify files in the working tree.
• Stage the changes you want to be included in the next commit.
• Commit changes. Committing will take the files from the index and
store them as a snapshot in the repository.
Eng. Amjad Mahfoud amjadoof@gmail.com 13
Three states of Git files
• Modified
• Staged
• Committed
When a file is first modified, the change can only be found in the working
tree.
You must stage the changes you want to be included in your next commit.
The index contains all file changes that will be committed.
Once you have finished staging files, commit them with a message describing
what you changed.
The modified files are now safely stored in the repo.
Eng. Amjad Mahfoud amjadoof@gmail.com 14
Getting Git
• Get the latest: http://git-scm.com
Eng. Amjad Mahfoud 15amjadoof@gmail.com
Creating a repository
After installing Git on your machine, the first thing you'll need to do is
set up a repository.
A repository (repo) is a centrally located folder for storing all your code.
Once you create a Git repository with your files and directories, you can
start tracking changes and versions.
In this section, you'll learn how to get a repository up and running.
Eng. Amjad Mahfoud amjadoof@gmail.com 16
Remote repositories and local repositories
• There are two types of Git repositories: remote and local.
• A remote repository is hosted on a remote, or off-site, server that is
shared among multiple team members.
• A local repository is hosted on a local machine for an individual user.
• While you can take advantage of Git version control features with a
local repository, collaboration features—like pulling and pushing code
changes with teammates—will be better suited on a remote
repository.
Eng. Amjad Mahfoud amjadoof@gmail.com 17
How to create a repository
• There are two ways to create a local repository on your machine. You
can create a new repository from scratch using a file folder on your
computer or clone an existing repository.
Eng. Amjad Mahfoud amjadoof@gmail.com 18
Git init
• You can create a new repo from scratch using the git init command. It
can be used to introduce Git into an existing, unversioned project in
order to start tracking changes.
Eng. Amjad Mahfoud amjadoof@gmail.com 19
Git clone
• Use the git clone command to copy a remote repository onto your
local machine.
• By default, git clone automatically sets up a local master branch that
tracks the remote master branch it was cloned from.
Eng. Amjad Mahfoud amjadoof@gmail.com 20
Recording changes
• Now that you understand how to create a git repository, you'll need to
know how to save file changes.
• It is important to note that Git does not automatically save every
change you make. You must tell Git which changes you want to be
recorded by staging those changes. After staging, you can commit the
changes so that they are recorded in the repo.
Eng. Amjad Mahfoud amjadoof@gmail.com 21
Making changes
• As we mentioned in the Git workflow section, changes are made in the
working tree—a directory consisting of the files you are currently
working on. The working tree is where you edit files, add new files,
and remove files that are no longer needed.
• All files that are changed in the working tree are noted as modified in
the index. An index is a staging area where new commits are prepared.
It sits between the repository and working tree.
• Changes made in the working tree will not be saved directly to the
repository. All changes must first be staged in the index in order to be
saved in the repo. Only the files in the index are committed to the
repo.
Eng. Amjad Mahfoud amjadoof@gmail.com 22
Git commit
• The git commit command enables you to record file changes in the
repository's Git history.
• By committing, you will be able to view all changes chronologically in
the respective file or directory.
Eng. Amjad Mahfoud amjadoof@gmail.com 23
Commands
Basic Git commands
24
Configure tooling
Eng. Amjad Mahfoud amjadoof@gmail.com 25
Configure user information for all local repositories
$ git config --global user.name "[name]"
Sets the name you want attached to your commit transactions
$ git config --global user.email "[email address]"
Sets the email you want attached to your commit transactions
Create repositories
Eng. Amjad Mahfoud amjadoof@gmail.com 26
Start a new repository or obtain one from an existing URL
$ git init [project-name]
Creates a new local repository with the specified name
$ git clone [url]
Downloads a project and its entire version history
Make changes
Eng. Amjad Mahfoud amjadoof@gmail.com 27
Review edits and craft a commit transaction
$ git status
Lists all new or modified files to be committed
$ git diff
Shows file differences not yet staged
$ git add [file]
Snapshots the file in preparation for versioning
Make changes
Eng. Amjad Mahfoud amjadoof@gmail.com 28
$ git diff --staged
Shows file differences between staging and the last file version
$ git reset [file]
Unstages the file, but preserves its contents
$ git commit -m"[descriptive message]"
Records file snapshots permanently in version history
Synchronize changes
Eng. Amjad Mahfoud amjadoof@gmail.com 29
Register a remote (URL) and exchange repository history
$ git fetch [remote]
Downloads all history from the remote repository
$ git merge [remote]/[branch]
Combines the remote branch into the current local branch
$ git push [remote] [branch]
Uploads all local branch commits to GitHub
$ git pull
Downloads bookmark history and incorporates changes
Commands
Recap
30
To use Git, developers use specific commands to copy, create, change,
and combine code. These commands can be executed directly from the
command line or by using an application like Git.
Here are some common commands for using Git:
Eng. Amjad Mahfoud amjadoof@gmail.com 31
• git init initializes a brand new Git repository and begins tracking an
existing directory. It adds a hidden subfolder within the existing
directory that houses the internal data structure required for version
control.
• git clone creates a local copy of a project that already exists remotely.
The clone includes all the project’s files, history, and branches.
Eng. Amjad Mahfoud amjadoof@gmail.com 32
• git add stages a change. Git tracks changes to a developer’s codebase,
but it’s necessary to stage and take a snapshot of the changes to
include them in the project’s history. This command performs staging,
the first part of that two-step process. Any changes that are staged will
become a part of the next snapshot and a part of the project’s history.
Staging and committing separately gives developers complete control
over the history of their project without changing how they code and
work.
Eng. Amjad Mahfoud amjadoof@gmail.com 33
• git commit saves the snapshot to the project history and completes
the change-tracking process. In short, a commit functions like taking a
photo. Anything that’s been staged with git add will become a part of
the snapshot with git commit.
• git status shows the status of changes as untracked, modified, or
staged.
• git branch shows the branches being worked on locally.
Eng. Amjad Mahfoud amjadoof@gmail.com 34
• git merge merges lines of development together. This command is typically
used to combine changes made on two distinct branches. For example, a
developer would merge when they want to combine changes from a feature
branch into the master branch for deployment.
• git pull updates the local line of development with updates from its remote
counterpart. Developers use this command if a teammate has made
commits to a branch on a remote, and they would like to reflect those
changes in their local environment.
• git push updates the remote repository with any commits made locally to a
branch.
Eng. Amjad Mahfoud amjadoof@gmail.com 35
For more information
• https://git-scm.com/docs
Eng. Amjad Mahfoud amjadoof@gmail.com 36
37
Thanks for listening
Eng. Amjad Mahfoud amjadoof@gmail.com

Contenu connexe

Tendances

Git Introduction
Git IntroductionGit Introduction
Git IntroductionGareth Hall
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to gitEmanuele Olivetti
 
Git for uninitiated
Git for uninitiatedGit for uninitiated
Git for uninitiatedJohn C. Chan
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Simplilearn
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with GitLuigi De Russis
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubBigBlueHat
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introductionrschwietzke
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open SourceLorna Mitchell
 
[Public] gerrit concepts and workflows
[Public] gerrit   concepts and workflows[Public] gerrit   concepts and workflows
[Public] gerrit concepts and workflowsYanbin Kong
 
Software Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and EclipseSoftware Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and EclipseHüseyin Ergin
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHubDSCVSSUT
 
Git Terminologies
Git TerminologiesGit Terminologies
Git TerminologiesYash
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hubNaveen Pandey
 
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, TrivandrumIntroduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, TrivandrumAbhijitNarayan2
 
Version control system
Version control systemVersion control system
Version control systemAndrew Liu
 
What the git? - SAP Inside Track Munich 2016
What the git?  - SAP Inside Track Munich 2016What the git?  - SAP Inside Track Munich 2016
What the git? - SAP Inside Track Munich 2016Hendrik Neumann
 

Tendances (20)

Git Introduction
Git IntroductionGit Introduction
Git Introduction
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Git for uninitiated
Git for uninitiatedGit for uninitiated
Git for uninitiated
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
 
Version Control with Git
Version Control with GitVersion Control with Git
Version Control with Git
 
Git introduction
Git introductionGit introduction
Git introduction
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introduction
 
Git, GitHub and Open Source
Git, GitHub and Open SourceGit, GitHub and Open Source
Git, GitHub and Open Source
 
Git presentation
Git presentationGit presentation
Git presentation
 
[Public] gerrit concepts and workflows
[Public] gerrit   concepts and workflows[Public] gerrit   concepts and workflows
[Public] gerrit concepts and workflows
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Software Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and EclipseSoftware Versioning with Bitbucket and Eclipse
Software Versioning with Bitbucket and Eclipse
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHub
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
 
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, TrivandrumIntroduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
Introduction to Git and Github - Google Developer Student Clubs CET, Trivandrum
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
Version control system
Version control systemVersion control system
Version control system
 
What the git? - SAP Inside Track Munich 2016
What the git?  - SAP Inside Track Munich 2016What the git?  - SAP Inside Track Munich 2016
What the git? - SAP Inside Track Munich 2016
 

Similaire à Git

Data science Git management
Data science Git managementData science Git management
Data science Git managementArindam Banerjee
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptxEshaan35
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor Kumar
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Gitatishgoswami
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticlePRIYATHAMDARISI
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptxtnscharishma
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 

Similaire à Git (20)

Data science Git management
Data science Git managementData science Git management
Data science Git management
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Git hub
Git hubGit hub
Git hub
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptx
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
 
setting up a repository using GIT
setting up a repository using GITsetting up a repository using GIT
setting up a repository using GIT
 
Git & Github
Git & GithubGit & Github
Git & Github
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Git and GitHub Info Session
Git and GitHub Info SessionGit and GitHub Info Session
Git and GitHub Info Session
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git Basics
Git BasicsGit Basics
Git Basics
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
Git overview
Git overviewGit overview
Git overview
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptx
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Advance workshop on git
Advance workshop on gitAdvance workshop on git
Advance workshop on git
 

Dernier

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Dernier (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Git

  • 1. GIT: A BRIEF INTRODUCTION Eng. Amjad Mahfoud amjadoof@gmail.com 8 - Nov - 2018 1
  • 2. Slides Structure Introduction What is GIT Using Git Basic Git commands Further Reading 2
  • 4. What is Git? • Git is a distributed version control system for managing source code. • Ok, so what is version control? • Simply put, version control is a system for tracking changes to files. • As you modify files, the version control system records and saves each change. • This allows you to restore a previous version of your code at any time. Eng. Amjad Mahfoud 4amjadoof@gmail.com
  • 5. What is Git? • Without a version control system, you are stuck manually saving multiple versions of your file using different dates and/or names (e.g. 12-02-2016-monkey_code.php; 12-03-2016-monkey_code.php). • This method is time-consuming and impractical when you are dealing with hundreds of files. Eng. Amjad Mahfoud 5amjadoof@gmail.com
  • 6. What is Git? • Renaming a file also doesn't give you any context as to what changes were made or who they were made by. • When multiple team members edit the same file, overwriting may occur and it becomes difficult to keep up with the latest file version. • With Git, you can easily follow your source code's revision history and track changes. • You can also go back in time to learn about how the version has changed and who has made the changes. • When the latest version of a file is on a shared repository, Git will prevent unintentional overwrites by anyone on your team who has an older version of the file. Eng. Amjad Mahfoud 6amjadoof@gmail.com
  • 7. Git makes it easy to: • Keep track of code history • Collaborate on code as a team • See who made which changes • Deploy to staging or production Eng. Amjad Mahfoud 7amjadoof@gmail.com
  • 8. Git workflow • There are three main components of a Git project: • Repository • Working tree • Index Eng. Amjad Mahfoud amjadoof@gmail.com 8
  • 9. The repository: or repo, is the “container” that tracks the changes to your project files. It holds all the commits—a snapshot of all your files at a point in time— that have been made. You can access the commit history with the Git log. Eng. Amjad Mahfoud amjadoof@gmail.com 9
  • 10. The working tree or working directory, consists of files that you are currently working on. You can think of a working tree as a file system where you can view and modify files. Eng. Amjad Mahfoud amjadoof@gmail.com 10
  • 11. The index or staging area, is where commits are prepared. The index compares the files in the working tree to the files in the repo. When you make a change in the working tree, the index marks the file as modified before it is committed. Eng. Amjad Mahfoud amjadoof@gmail.com 11
  • 12. The three main components of a Git project: the repository, index, and working tree. Eng. Amjad Mahfoud amjadoof@gmail.com 12
  • 13. The basic Git workflow: • Modify files in the working tree. • Stage the changes you want to be included in the next commit. • Commit changes. Committing will take the files from the index and store them as a snapshot in the repository. Eng. Amjad Mahfoud amjadoof@gmail.com 13
  • 14. Three states of Git files • Modified • Staged • Committed When a file is first modified, the change can only be found in the working tree. You must stage the changes you want to be included in your next commit. The index contains all file changes that will be committed. Once you have finished staging files, commit them with a message describing what you changed. The modified files are now safely stored in the repo. Eng. Amjad Mahfoud amjadoof@gmail.com 14
  • 15. Getting Git • Get the latest: http://git-scm.com Eng. Amjad Mahfoud 15amjadoof@gmail.com
  • 16. Creating a repository After installing Git on your machine, the first thing you'll need to do is set up a repository. A repository (repo) is a centrally located folder for storing all your code. Once you create a Git repository with your files and directories, you can start tracking changes and versions. In this section, you'll learn how to get a repository up and running. Eng. Amjad Mahfoud amjadoof@gmail.com 16
  • 17. Remote repositories and local repositories • There are two types of Git repositories: remote and local. • A remote repository is hosted on a remote, or off-site, server that is shared among multiple team members. • A local repository is hosted on a local machine for an individual user. • While you can take advantage of Git version control features with a local repository, collaboration features—like pulling and pushing code changes with teammates—will be better suited on a remote repository. Eng. Amjad Mahfoud amjadoof@gmail.com 17
  • 18. How to create a repository • There are two ways to create a local repository on your machine. You can create a new repository from scratch using a file folder on your computer or clone an existing repository. Eng. Amjad Mahfoud amjadoof@gmail.com 18
  • 19. Git init • You can create a new repo from scratch using the git init command. It can be used to introduce Git into an existing, unversioned project in order to start tracking changes. Eng. Amjad Mahfoud amjadoof@gmail.com 19
  • 20. Git clone • Use the git clone command to copy a remote repository onto your local machine. • By default, git clone automatically sets up a local master branch that tracks the remote master branch it was cloned from. Eng. Amjad Mahfoud amjadoof@gmail.com 20
  • 21. Recording changes • Now that you understand how to create a git repository, you'll need to know how to save file changes. • It is important to note that Git does not automatically save every change you make. You must tell Git which changes you want to be recorded by staging those changes. After staging, you can commit the changes so that they are recorded in the repo. Eng. Amjad Mahfoud amjadoof@gmail.com 21
  • 22. Making changes • As we mentioned in the Git workflow section, changes are made in the working tree—a directory consisting of the files you are currently working on. The working tree is where you edit files, add new files, and remove files that are no longer needed. • All files that are changed in the working tree are noted as modified in the index. An index is a staging area where new commits are prepared. It sits between the repository and working tree. • Changes made in the working tree will not be saved directly to the repository. All changes must first be staged in the index in order to be saved in the repo. Only the files in the index are committed to the repo. Eng. Amjad Mahfoud amjadoof@gmail.com 22
  • 23. Git commit • The git commit command enables you to record file changes in the repository's Git history. • By committing, you will be able to view all changes chronologically in the respective file or directory. Eng. Amjad Mahfoud amjadoof@gmail.com 23
  • 25. Configure tooling Eng. Amjad Mahfoud amjadoof@gmail.com 25 Configure user information for all local repositories $ git config --global user.name "[name]" Sets the name you want attached to your commit transactions $ git config --global user.email "[email address]" Sets the email you want attached to your commit transactions
  • 26. Create repositories Eng. Amjad Mahfoud amjadoof@gmail.com 26 Start a new repository or obtain one from an existing URL $ git init [project-name] Creates a new local repository with the specified name $ git clone [url] Downloads a project and its entire version history
  • 27. Make changes Eng. Amjad Mahfoud amjadoof@gmail.com 27 Review edits and craft a commit transaction $ git status Lists all new or modified files to be committed $ git diff Shows file differences not yet staged $ git add [file] Snapshots the file in preparation for versioning
  • 28. Make changes Eng. Amjad Mahfoud amjadoof@gmail.com 28 $ git diff --staged Shows file differences between staging and the last file version $ git reset [file] Unstages the file, but preserves its contents $ git commit -m"[descriptive message]" Records file snapshots permanently in version history
  • 29. Synchronize changes Eng. Amjad Mahfoud amjadoof@gmail.com 29 Register a remote (URL) and exchange repository history $ git fetch [remote] Downloads all history from the remote repository $ git merge [remote]/[branch] Combines the remote branch into the current local branch $ git push [remote] [branch] Uploads all local branch commits to GitHub $ git pull Downloads bookmark history and incorporates changes
  • 31. To use Git, developers use specific commands to copy, create, change, and combine code. These commands can be executed directly from the command line or by using an application like Git. Here are some common commands for using Git: Eng. Amjad Mahfoud amjadoof@gmail.com 31
  • 32. • git init initializes a brand new Git repository and begins tracking an existing directory. It adds a hidden subfolder within the existing directory that houses the internal data structure required for version control. • git clone creates a local copy of a project that already exists remotely. The clone includes all the project’s files, history, and branches. Eng. Amjad Mahfoud amjadoof@gmail.com 32
  • 33. • git add stages a change. Git tracks changes to a developer’s codebase, but it’s necessary to stage and take a snapshot of the changes to include them in the project’s history. This command performs staging, the first part of that two-step process. Any changes that are staged will become a part of the next snapshot and a part of the project’s history. Staging and committing separately gives developers complete control over the history of their project without changing how they code and work. Eng. Amjad Mahfoud amjadoof@gmail.com 33
  • 34. • git commit saves the snapshot to the project history and completes the change-tracking process. In short, a commit functions like taking a photo. Anything that’s been staged with git add will become a part of the snapshot with git commit. • git status shows the status of changes as untracked, modified, or staged. • git branch shows the branches being worked on locally. Eng. Amjad Mahfoud amjadoof@gmail.com 34
  • 35. • git merge merges lines of development together. This command is typically used to combine changes made on two distinct branches. For example, a developer would merge when they want to combine changes from a feature branch into the master branch for deployment. • git pull updates the local line of development with updates from its remote counterpart. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment. • git push updates the remote repository with any commits made locally to a branch. Eng. Amjad Mahfoud amjadoof@gmail.com 35
  • 36. For more information • https://git-scm.com/docs Eng. Amjad Mahfoud amjadoof@gmail.com 36
  • 37. 37 Thanks for listening Eng. Amjad Mahfoud amjadoof@gmail.com