SlideShare a Scribd company logo
1 of 35
Download to read offline
GIT BASICS
How to quickly use Git for day to day developments
...
AND STASH
Leverage Git on the Enterprise
Created by /
Original presentation on
François D'Agostini @DagoFrancesco
GitHub
WHAT IS GIT ?
DISTRIBUTED VERSION CONTROL
Speed
Simple
Non Linear Development
Fully Distributed
Large Projects
SNAPSHOT BASED, NOT DELTAS
DIFFERENT FROMCVS,SVN...
GIT CONFIGURATION
--system: /etc/gitconfig
--global: ~/.gitconfig
default: repo/.git/config
COLORS IN LINUX:
gitconfig--globaluser.name"FrançoisD'Agostini"
gitconfig--globaluser.email"fdagosti@nds.com"
gitconfig--globalcolor.uialways
CREATION OF A REPO
No need for network
Can do a lot locally on PC
Best for testing
Git init: repo + working directory
git init --bare: Repo only
git clone:From an existing repo
EXAMPLE: FIRST COMMIT
mkdirgit-tests
gitinitjohn.git
gitconfiguser.name"johnDoe"
gitconfiguser.email"john@example.com"
echo"firstlinefromJohn">file1
gitaddfile1
gitstatus
gitcommit-m"initialcommitfromJohn"
ANOTHER COMMIT
cat>>file1
SecondCommitfromJohn
gitcommit-a-m"anothercommit"
WORKING DIRECTORY, INDEXES AND
COMMITS
VIEWING COMMITS HISTORY
...lots of other options !!
git blame: one files only
gitk: for graphic visualization
same options as git log
gitlog
--decorate
--graph
--stat
--oneline
-n
COMMITS HISTORY (2)
git show: details about a commit by default, shows the detail
of the most recent commit
git show-branch: show details about the current branch
HANDY ALIAS
gitconfig--globalalias.graph"log--decorate--graph--oneline"
VIEWING COMMIT DIFFERENCES
git diff: differences between the working directory and the
index
--cached: between the index and the most recent commit
HEAD: between the working directory and the most recent
commit
CANCELLATION, RESTORATION, CLEANING
git reset: cancels changes about to be commited in the
index
--hard: changes also the working directory
git checkout: cancels changes made to working directory
compared to index
git clean: deletes files not followed by Git.
-f option to really delete them
-n to simulate
.gitignore file: to avoid Git to track useless files
BRANCH MANAGEMENT
A Branch is just a pointer to a commit
nothing fancy
very lightweight
very similar to "tags"
stored in .git/refs/[heads|remotes|tags]
Default branch name: master
BRANCH MANAGEMENT (2)
git branch: list branches
-r: remote branches as well
-a all branches
git branch dev: create branch "dev"
Does not change the current branch
git checkout dev: move the current branch to the "dev"
branch
-b: create the branch while switching to it
MERGING
git merge dev:merges "dev" branch into current branch
does not destroy "dev"
git branch -d dev:deletes the "dev" branch
only deletes the pointer
can be deleted only if the branch is accessible from the
current branch
This is usually what is needed after merging. The old
"dev" pointer is no longer useful
in case of future branching, a new branch can be
created
CONFLICT RESOLUTION
git merge can lead to conflicts if the same file has been
modified in two branches
manual conflict resolution is needed on this files
conflict markers are added by git and need to be removed
by the developper
git add on the conflict files
git commit to end the merge
and of course, delete the merged branch
if conflict resolution is too complex:
git merge --abort: restores the working directory to the
state it was prior to merge
REMOTE REPOSITORIES
git remote: lists all remote repos linked to the current
local repo
git remote add name url: adds the specified url as a
remote repo to the local repo
No need in case repo has been created with git clone
git push repo: push local commits on the current branch to
the same branch on the remote repo
warning: the remote repo must already have the same
branch, else use git push repo branch
REMOTES: FETCHING AND PULLING
There is a separate copy of the remote commits separated
from the local branch
Can be seen using git branch -a
this means that the remote and the local copy can easily
be compared
git fetch repo: updates the local copy of the remote repo
git pull: like git fetch, but also merges the remote commit
into this repo's branch
this one can lead to conflicts
GIT REBASE
When fetching commits from remote repos, there are two
ways to merge them:
regular merge: it will create a new commit every time
rebase: it will not create a new commit
allows to change the commits that were not published to
have new parents
very handy when you need to integrate other people
changes but continu your work
use: git rebase branch
git pull --rebase: will use the reboase algorithm in case of
conflicts instead of merge
STASH: SAVE YOUR WORK WHILE SWITCHING
CONTEXT
Allows to save your current context and switch work
Then, you can restore the exact state back
git stash save messages: stores the working director and
the index into a stack
git stash list: lists all the saved stacks
git stash show: shows the details of a stack item
git stash pop: pops a state and applies it on the current
working directory
git stash drop: removes an item on the stack
STASH (2)
warning, stashing does not store the branch state
This means that you can recover your state on any branch
popping a state can create conflicts that needs to be
merged
if a pop failed because of a conflict, it will need to be
removed manually
GIT HOSTING IN THE
COMPANY
Different from git stash seen previously !!
STASH
WHY NEED A GIT HOSTING TOOL?
Git alone is not sufficient
To improve knowledge sharing
to improve code visibility
to get the code out of the darkness !!
STASH CARACTERISTICS
Structuring projects, repos and roles
Browse files, branches, commits and tags
Code Reviews concepts: Pull requests
Repos forking
private repos
Jira linking
PROJECT STRUCTURES
Stash organized by projects that handles multiple repos
permissions are based on projects and repos. Allows for
decentralized admin
users have roles: project creators, admins, system admins,
writer
Soon, anonymous mode
FILE BROWSING
Can browser any file and see source code
Allows to change branches and tags
Can have details of each commit
browse list of commits and log
markdown support to explain source code organization
PULL REQUESTS
Implements best practices with respect to code review
Allows anyone to create a branch, make some code and
ask for its merge
Branch permissions allows to control commits
Pull requests allow to review, make comments, ammend
new commits, see diffs...
Anyone can watch a pull request and be notified
Pull requests can be declined or accepted
FORKING
fork a repo into another repo, but keep history
allows for later merges
PRIVATE REPOS
Develop your own projects
can show or hide repos to others
JIRA LINK
Allows to link Git commit to Jira issues
from a Jira issue, see all related commits
with Git hooks, you can force it
BRANCHING STRATEGIES WITH GIT
Git is small tool that does not come with a whole
environment and rules (think Clearcase...)
Git is versatile and can be used in a dozen of different
ways
Git itself does not enforce how to use branches and how
to work as a team. It keeps this open
But how a serious company is supposed to use git for all its
projects without going messy ?
WENEED BEST PRACTICES !!
GIT FLOW
Standard usages of branches when working with Git
Used in Big projects, with many developers working on it
MAIN CARACTERISTICS
2 long lived branches : Develop and master
3 short lived branches: Feature, Release and HotFix
The master branch is restricted to commit by one or two
people
The Develop branch is restricted to senior developers
New code is added through Feature branches only
STEPS TO FOLLOW
Create a Feature branch, name it to the story/feature you
are working on
once you are happy with your features, you create a pull
request to merge it
STEPS TO FOLLOW (2)
When a release must be done, use a temporary release
branch
The Master branch is used only for "stable" version
commits. Any commits on master should have a Tag
If a bug is found on Master, a "HotFix branch is created to
correct it and merge it back on master

More Related Content

What's hot

Git - Simplified For Testers
Git - Simplified For TestersGit - Simplified For Testers
Git - Simplified For Testersupadhyay_25
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentationMack Hardy
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Branch to branch by Photis Patriotis
Branch to branch by Photis PatriotisBranch to branch by Photis Patriotis
Branch to branch by Photis PatriotisProlific Interactive
 
Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?John Congdon
 
Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)Yeasin Abedin
 
Introduction to github slideshare
Introduction to github slideshareIntroduction to github slideshare
Introduction to github slideshareRakesh Sukumar
 
Git Ready! Workflows
Git Ready! WorkflowsGit Ready! Workflows
Git Ready! WorkflowsAtlassian
 
Git Workflow With Gitflow
Git Workflow With GitflowGit Workflow With Gitflow
Git Workflow With GitflowJosh Dvir
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierChristoph Matthies
 
Git for Beginners
Git for BeginnersGit for Beginners
Git for BeginnersRick Umali
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerLuca Milanesio
 
Using Github for DSpace development
Using Github for DSpace developmentUsing Github for DSpace development
Using Github for DSpace developmentBram Luyten
 
Git introduction for Beginners
Git introduction for BeginnersGit introduction for Beginners
Git introduction for BeginnersMortezaTaghaddomi
 
A successful Git branching model
A successful Git branching model A successful Git branching model
A successful Git branching model abodeltae
 

What's hot (20)

Git best practices 2016
Git best practices 2016Git best practices 2016
Git best practices 2016
 
Git flow
Git flowGit flow
Git flow
 
Git - Simplified For Testers
Git - Simplified For TestersGit - Simplified For Testers
Git - Simplified For Testers
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentation
 
Git & Github
Git & GithubGit & Github
Git & Github
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Branch to branch by Photis Patriotis
Branch to branch by Photis PatriotisBranch to branch by Photis Patriotis
Branch to branch by Photis Patriotis
 
Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git usage (Basics and workflow)
Git usage (Basics and workflow)Git usage (Basics and workflow)
Git usage (Basics and workflow)
 
Introduction to github slideshare
Introduction to github slideshareIntroduction to github slideshare
Introduction to github slideshare
 
Git Ready! Workflows
Git Ready! WorkflowsGit Ready! Workflows
Git Ready! Workflows
 
Git Workflow With Gitflow
Git Workflow With GitflowGit Workflow With Gitflow
Git Workflow With Gitflow
 
Git workflows
Git workflowsGit workflows
Git workflows
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easier
 
Git for Beginners
Git for BeginnersGit for Beginners
Git for Beginners
 
Gerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and DockerGerrit is Getting Native with RPM, Deb and Docker
Gerrit is Getting Native with RPM, Deb and Docker
 
Using Github for DSpace development
Using Github for DSpace developmentUsing Github for DSpace development
Using Github for DSpace development
 
Git introduction for Beginners
Git introduction for BeginnersGit introduction for Beginners
Git introduction for Beginners
 
A successful Git branching model
A successful Git branching model A successful Git branching model
A successful Git branching model
 

Similar to Git basics a starter on git and its ecosystem

01 git interview questions & answers
01   git interview questions & answers01   git interview questions & answers
01 git interview questions & answersDeepQuest Software
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow Sebin Benjamin
 
Git for developers
Git for developersGit for developers
Git for developersHacen Dadda
 
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
 
devops-complete-notes-2.pdf
devops-complete-notes-2.pdfdevops-complete-notes-2.pdf
devops-complete-notes-2.pdfRobinRohit2
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperJohn Stevenson
 
Git_tutorial.pdf
Git_tutorial.pdfGit_tutorial.pdf
Git_tutorial.pdfAliaaTarek5
 
Git essential training & sharing self
Git essential training & sharing selfGit essential training & sharing self
Git essential training & sharing selfChen-Tien Tsai
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced gitGerrit Wanderer
 
git-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdfgit-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdfmurad khan
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03Gourav Varma
 
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a gitVincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a gitVincitOy
 
git github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxAbelPhilipJoseph
 

Similar to Git basics a starter on git and its ecosystem (20)

01 git interview questions & answers
01   git interview questions & answers01   git interview questions & answers
01 git interview questions & answers
 
Introducing Git and git flow
Introducing Git and git flow Introducing Git and git flow
Introducing Git and git flow
 
Git for developers
Git for developersGit for developers
Git for developers
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Mastering GIT
Mastering GITMastering GIT
Mastering GIT
 
devops-complete-notes-2.pdf
devops-complete-notes-2.pdfdevops-complete-notes-2.pdf
devops-complete-notes-2.pdf
 
Git and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern DeveloperGit and github - Verson Control for the Modern Developer
Git and github - Verson Control for the Modern Developer
 
Git_tutorial.pdf
Git_tutorial.pdfGit_tutorial.pdf
Git_tutorial.pdf
 
Git essential training & sharing self
Git essential training & sharing selfGit essential training & sharing self
Git essential training & sharing self
 
Checkitmobile advanced git
Checkitmobile advanced gitCheckitmobile advanced git
Checkitmobile advanced git
 
git-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdfgit-commands-cheat-sheet-infopediya-com.pdf
git-commands-cheat-sheet-infopediya-com.pdf
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
 
Git essentials
Git essentialsGit essentials
Git essentials
 
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a gitVincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
Vincit Teatime 2015.2 - Otto Kekäläinen: Don't be a git
 
Git github
Git githubGit github
Git github
 
Git & GitLab
Git & GitLabGit & GitLab
Git & GitLab
 
Git basics
Git basicsGit basics
Git basics
 
git github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptxgit github PPT_GDSCIIITK.pptx
git github PPT_GDSCIIITK.pptx
 

Recently uploaded

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Git basics a starter on git and its ecosystem

  • 1. GIT BASICS How to quickly use Git for day to day developments ... AND STASH Leverage Git on the Enterprise Created by / Original presentation on François D'Agostini @DagoFrancesco GitHub
  • 2. WHAT IS GIT ? DISTRIBUTED VERSION CONTROL Speed Simple Non Linear Development Fully Distributed Large Projects
  • 3. SNAPSHOT BASED, NOT DELTAS DIFFERENT FROMCVS,SVN...
  • 4. GIT CONFIGURATION --system: /etc/gitconfig --global: ~/.gitconfig default: repo/.git/config COLORS IN LINUX: gitconfig--globaluser.name"FrançoisD'Agostini" gitconfig--globaluser.email"fdagosti@nds.com" gitconfig--globalcolor.uialways
  • 5. CREATION OF A REPO No need for network Can do a lot locally on PC Best for testing Git init: repo + working directory git init --bare: Repo only git clone:From an existing repo
  • 9. VIEWING COMMITS HISTORY ...lots of other options !! git blame: one files only gitk: for graphic visualization same options as git log gitlog --decorate --graph --stat --oneline -n
  • 10. COMMITS HISTORY (2) git show: details about a commit by default, shows the detail of the most recent commit git show-branch: show details about the current branch HANDY ALIAS gitconfig--globalalias.graph"log--decorate--graph--oneline"
  • 11. VIEWING COMMIT DIFFERENCES git diff: differences between the working directory and the index --cached: between the index and the most recent commit HEAD: between the working directory and the most recent commit
  • 12. CANCELLATION, RESTORATION, CLEANING git reset: cancels changes about to be commited in the index --hard: changes also the working directory git checkout: cancels changes made to working directory compared to index git clean: deletes files not followed by Git. -f option to really delete them -n to simulate .gitignore file: to avoid Git to track useless files
  • 13. BRANCH MANAGEMENT A Branch is just a pointer to a commit nothing fancy very lightweight very similar to "tags" stored in .git/refs/[heads|remotes|tags] Default branch name: master
  • 14. BRANCH MANAGEMENT (2) git branch: list branches -r: remote branches as well -a all branches git branch dev: create branch "dev" Does not change the current branch git checkout dev: move the current branch to the "dev" branch -b: create the branch while switching to it
  • 15. MERGING git merge dev:merges "dev" branch into current branch does not destroy "dev" git branch -d dev:deletes the "dev" branch only deletes the pointer can be deleted only if the branch is accessible from the current branch This is usually what is needed after merging. The old "dev" pointer is no longer useful in case of future branching, a new branch can be created
  • 16. CONFLICT RESOLUTION git merge can lead to conflicts if the same file has been modified in two branches manual conflict resolution is needed on this files conflict markers are added by git and need to be removed by the developper git add on the conflict files git commit to end the merge and of course, delete the merged branch if conflict resolution is too complex: git merge --abort: restores the working directory to the state it was prior to merge
  • 17. REMOTE REPOSITORIES git remote: lists all remote repos linked to the current local repo git remote add name url: adds the specified url as a remote repo to the local repo No need in case repo has been created with git clone git push repo: push local commits on the current branch to the same branch on the remote repo warning: the remote repo must already have the same branch, else use git push repo branch
  • 18. REMOTES: FETCHING AND PULLING There is a separate copy of the remote commits separated from the local branch Can be seen using git branch -a this means that the remote and the local copy can easily be compared git fetch repo: updates the local copy of the remote repo git pull: like git fetch, but also merges the remote commit into this repo's branch this one can lead to conflicts
  • 19. GIT REBASE When fetching commits from remote repos, there are two ways to merge them: regular merge: it will create a new commit every time rebase: it will not create a new commit allows to change the commits that were not published to have new parents very handy when you need to integrate other people changes but continu your work use: git rebase branch git pull --rebase: will use the reboase algorithm in case of conflicts instead of merge
  • 20. STASH: SAVE YOUR WORK WHILE SWITCHING CONTEXT Allows to save your current context and switch work Then, you can restore the exact state back git stash save messages: stores the working director and the index into a stack git stash list: lists all the saved stacks git stash show: shows the details of a stack item git stash pop: pops a state and applies it on the current working directory git stash drop: removes an item on the stack
  • 21. STASH (2) warning, stashing does not store the branch state This means that you can recover your state on any branch popping a state can create conflicts that needs to be merged if a pop failed because of a conflict, it will need to be removed manually
  • 22. GIT HOSTING IN THE COMPANY Different from git stash seen previously !! STASH
  • 23. WHY NEED A GIT HOSTING TOOL? Git alone is not sufficient To improve knowledge sharing to improve code visibility to get the code out of the darkness !!
  • 24. STASH CARACTERISTICS Structuring projects, repos and roles Browse files, branches, commits and tags Code Reviews concepts: Pull requests Repos forking private repos Jira linking
  • 25. PROJECT STRUCTURES Stash organized by projects that handles multiple repos permissions are based on projects and repos. Allows for decentralized admin users have roles: project creators, admins, system admins, writer Soon, anonymous mode
  • 26. FILE BROWSING Can browser any file and see source code Allows to change branches and tags Can have details of each commit browse list of commits and log markdown support to explain source code organization
  • 27. PULL REQUESTS Implements best practices with respect to code review Allows anyone to create a branch, make some code and ask for its merge Branch permissions allows to control commits Pull requests allow to review, make comments, ammend new commits, see diffs... Anyone can watch a pull request and be notified Pull requests can be declined or accepted
  • 28. FORKING fork a repo into another repo, but keep history allows for later merges
  • 29. PRIVATE REPOS Develop your own projects can show or hide repos to others
  • 30. JIRA LINK Allows to link Git commit to Jira issues from a Jira issue, see all related commits with Git hooks, you can force it
  • 31. BRANCHING STRATEGIES WITH GIT Git is small tool that does not come with a whole environment and rules (think Clearcase...) Git is versatile and can be used in a dozen of different ways Git itself does not enforce how to use branches and how to work as a team. It keeps this open But how a serious company is supposed to use git for all its projects without going messy ? WENEED BEST PRACTICES !!
  • 32. GIT FLOW Standard usages of branches when working with Git Used in Big projects, with many developers working on it
  • 33. MAIN CARACTERISTICS 2 long lived branches : Develop and master 3 short lived branches: Feature, Release and HotFix The master branch is restricted to commit by one or two people The Develop branch is restricted to senior developers New code is added through Feature branches only
  • 34. STEPS TO FOLLOW Create a Feature branch, name it to the story/feature you are working on once you are happy with your features, you create a pull request to merge it
  • 35. STEPS TO FOLLOW (2) When a release must be done, use a temporary release branch The Master branch is used only for "stable" version commits. Any commits on master should have a Tag If a bug is found on Master, a "HotFix branch is created to correct it and merge it back on master