SlideShare a Scribd company logo
Introduction into Git
Serhii Kartashov
December 2015
Softjourn
Internship
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Types of Version Control Systems (VCS)
Distributed Version ControlCentralized Version Control
server
client client
repo
repo repo
Fundamental Concepts
• repository
• working copy
• conflicts
• merging changes
• development (branching) model
tag dev feature
origin
git repo
git repo git repo
commit
branch
repo
git repo git repo
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
How to start working with Git
• Install Git client (see useful links at the end)
– git --version
• Config you client
– git config --global user.name “Serhii Kartashov“
– git config --global user.email Serhii.Kartashov@example.com
– git config --list (check your settings)
• Clone a branch from a repository
– git clone https://myrepo.com/repo workdir
• Initialize your local repo and link to remote repo
– git init
– git remote add <my_fork> <url>
• Use git help command
– git help clone (launches browser to display HTML with instructions on how to
use this clone command)
• You may add .gitignore file to ignore some files, i.e. <*.jar>
Life cycle of files in your repo
Saving Changes
• Adding files to stage area:
– git add <file>
– git add <directory>
– git add --all
• Commit the staged snapshot to the project
history:
– git commit -m “<message>”
– git commit –a (will open text editor - vi)
Inspecting a Repository
• Display a status of working directory and the
staging are:
– git status
• Display committed snapshots:
– git log
– git log --oneline
– git log -p <file>
– git log --stat
– git log –graph --decorate –oneline
– git log –author=“Serhii Kartashov”
Undoing Changes. revert
• Undo a committed snapshot.
– git revert <commit>
But, instead of removing the commit from the
project history, it figures out how to undo the
changes introduced by the commit and appends
a new commit with the resulting content.
Undoing Changes, reset
• edit two files, stage one
• run git reset HEAD to undo the stage
• re-stage the file and commit
• run git reset --soft HEAD~ to undo the commit
but keep the staged files; commit again
• run git reset HEAD~ to undo the commit and all
staging; commit again
• run git reset --hard HEAD~ to lose the commit
and all that work
Undoing Changes, clean
• Remove untracked files from your working
directory
– git clean –n (just shows you what may be
removed)
– git clean -f (files only)
– git clean –df (files and directories)
Rewriting history
The git commit --amend command is a
convenient way to fix up the most recent
commit.
It lets you combine staged changes with the
previous commit instead of committing it as an
entirely new snapshot.
Rewriting history, rebase
• Rebasing is the process of moving a branch to
a new base commit.
– git rebase <base>
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Development (branching) model
• Branch convention:
– master
– develop
– release-* (tags)
– hotfix-*
Using Branches, branch
The git branch command lets you create, list,
rename, and delete branches. It doesn’t let you
switch between branches or put a forked
history back together again.
– git branch (list branches)
– git branch <branch> (create new branch)
– git branch -d <branch> (delete the specified
branch)
– git branch -m <branch> (rename the current
branch to <branch>)
Using branches, checkout
The git checkout command lets you navigate
between the branches created by git branch.
– git checkout <existing-branch>
– git checkout -b <new-branch>
Using Branches, merge
The git merge command lets you take the
independent lines of development created by
git branch and integrate them into a single
branch.
– git merge <branch>
– git merge --no-ff <branch> (merge the specified
branch into the current branch, but always
generate a merge commit)
Git Work Flow Cycle
clone repo
create,
checkout
branch
make
changes
update
branch
add files
to stage
commit
staged
files
push
commits
to
repo/fork
create pull
request
Clone repository
• git clone
• git init
• git remote
Create/Checkout branch
• git branch
• git checkout
Make changes
• git add
• git reset
Update branch
• git diff
• git fetch
• git rebase
Commit changes
• git commit
Push changes to repo
• git push
Agenda
Fundamental Concepts of VCS
Git
Development Model
Advanced Tips
Stashing
• Stash the changes in a dirty working directory
away
– git stash
– git stash list
– git stash apply
– git stash show <stash_name>
– git stash drop <stash_name>
– git stash branch testchanges
– git stash clear
Filtering and Formatting Logs
• git shortlog
• git log --graph --oneline --decorate
• git log -3 (display only the 3 most recent
commits)
• git log --after="2014-7-1“ (by date)
• git log --author="John|Mary“
• git log --grep="JRA-228:“ (by name)
• git log -S"Hello, World!" (by content)
Useful links
• Git clients
– http://git-scm.com/downloads (required)
– https://code.google.com/p/tortoisegit/wiki/Download
• Useful Git resources
– https://www.atlassian.com/git/tutorials/setting-up-a-
repository/#!overview
– http://ndpsoftware.com/git-cheatsheet.html#loc=workspace
– https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf
– Squash several Git commits into a single commit
• Git books and docs
– http://git-scm.com/book
– Command’s list http://git-scm.com/docs
– http://git-scm.com/documentation
Home Work. Git
1. Work Cycle:
1. create and init remote repository (set-url);
2. checkout branch and create new one;
3. rename branch;
4. create new files and add it to git;
5. commit changes and push them to remote repo;
6. use reset command (stage, commit, etc.)
7. use stash command (list, drop, save, pop, branch)
2. Branches:
1. copy new branch from created before (task 1);
2. apply changes in new branch and commit it (create possible
conflict between them);
3. merge changes in the second branch into first one.
Introduction into Git

More Related Content

What's hot

Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
LearningTech
 

What's hot (20)

Git basics
Git basicsGit basics
Git basics
 
Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
Git
GitGit
Git
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git undo
Git undoGit undo
Git undo
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
 
Git
GitGit
Git
 
Git tutorial II
Git tutorial IIGit tutorial II
Git tutorial II
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git 101
Git 101Git 101
Git 101
 
01 - Git vs SVN
01 - Git vs SVN01 - Git vs SVN
01 - Git vs SVN
 
Git-ing out of your git messes
Git-ing out of  your git messesGit-ing out of  your git messes
Git-ing out of your git messes
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git basic
Git basicGit basic
Git basic
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Undoing Things in Git
Undoing Things in GitUndoing Things in Git
Undoing Things in Git
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git presentation
Git presentationGit presentation
Git presentation
 

Similar to Introduction into Git

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 

Similar to Introduction into Git (20)

Git
Git Git
Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
GIT.pptx
GIT.pptxGIT.pptx
GIT.pptx
 
Git in a nutshell
Git in a nutshellGit in a nutshell
Git in a nutshell
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
git.ppt.pdf
git.ppt.pdfgit.ppt.pdf
git.ppt.pdf
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Git basic commands
Git basic commandsGit basic commands
Git basic commands
 
Git training v10
Git training v10Git training v10
Git training v10
 
Version control git day02
Version control   git day02Version control   git day02
Version control git day02
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Version control git day03
Version control   git day03Version control   git day03
Version control git day03
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Git Tech Talk
Git  Tech TalkGit  Tech Talk
Git Tech Talk
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 

Recently uploaded (20)

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Breaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdfBreaking the Code : A Guide to WhatsApp Business API.pdf
Breaking the Code : A Guide to WhatsApp Business API.pdf
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 

Introduction into Git

  • 1. Introduction into Git Serhii Kartashov December 2015 Softjourn Internship
  • 2. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 3. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 4. Types of Version Control Systems (VCS) Distributed Version ControlCentralized Version Control server client client repo repo repo
  • 5. Fundamental Concepts • repository • working copy • conflicts • merging changes • development (branching) model tag dev feature origin git repo git repo git repo commit branch repo git repo git repo
  • 6. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 7. How to start working with Git • Install Git client (see useful links at the end) – git --version • Config you client – git config --global user.name “Serhii Kartashov“ – git config --global user.email Serhii.Kartashov@example.com – git config --list (check your settings) • Clone a branch from a repository – git clone https://myrepo.com/repo workdir • Initialize your local repo and link to remote repo – git init – git remote add <my_fork> <url> • Use git help command – git help clone (launches browser to display HTML with instructions on how to use this clone command) • You may add .gitignore file to ignore some files, i.e. <*.jar>
  • 8. Life cycle of files in your repo
  • 9. Saving Changes • Adding files to stage area: – git add <file> – git add <directory> – git add --all • Commit the staged snapshot to the project history: – git commit -m “<message>” – git commit –a (will open text editor - vi)
  • 10. Inspecting a Repository • Display a status of working directory and the staging are: – git status • Display committed snapshots: – git log – git log --oneline – git log -p <file> – git log --stat – git log –graph --decorate –oneline – git log –author=“Serhii Kartashov”
  • 11. Undoing Changes. revert • Undo a committed snapshot. – git revert <commit> But, instead of removing the commit from the project history, it figures out how to undo the changes introduced by the commit and appends a new commit with the resulting content.
  • 12. Undoing Changes, reset • edit two files, stage one • run git reset HEAD to undo the stage • re-stage the file and commit • run git reset --soft HEAD~ to undo the commit but keep the staged files; commit again • run git reset HEAD~ to undo the commit and all staging; commit again • run git reset --hard HEAD~ to lose the commit and all that work
  • 13. Undoing Changes, clean • Remove untracked files from your working directory – git clean –n (just shows you what may be removed) – git clean -f (files only) – git clean –df (files and directories)
  • 14. Rewriting history The git commit --amend command is a convenient way to fix up the most recent commit. It lets you combine staged changes with the previous commit instead of committing it as an entirely new snapshot.
  • 15. Rewriting history, rebase • Rebasing is the process of moving a branch to a new base commit. – git rebase <base>
  • 16. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 17. Development (branching) model • Branch convention: – master – develop – release-* (tags) – hotfix-*
  • 18. Using Branches, branch The git branch command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. – git branch (list branches) – git branch <branch> (create new branch) – git branch -d <branch> (delete the specified branch) – git branch -m <branch> (rename the current branch to <branch>)
  • 19. Using branches, checkout The git checkout command lets you navigate between the branches created by git branch. – git checkout <existing-branch> – git checkout -b <new-branch>
  • 20. Using Branches, merge The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch. – git merge <branch> – git merge --no-ff <branch> (merge the specified branch into the current branch, but always generate a merge commit)
  • 21. Git Work Flow Cycle clone repo create, checkout branch make changes update branch add files to stage commit staged files push commits to repo/fork create pull request Clone repository • git clone • git init • git remote Create/Checkout branch • git branch • git checkout Make changes • git add • git reset Update branch • git diff • git fetch • git rebase Commit changes • git commit Push changes to repo • git push
  • 22. Agenda Fundamental Concepts of VCS Git Development Model Advanced Tips
  • 23. Stashing • Stash the changes in a dirty working directory away – git stash – git stash list – git stash apply – git stash show <stash_name> – git stash drop <stash_name> – git stash branch testchanges – git stash clear
  • 24. Filtering and Formatting Logs • git shortlog • git log --graph --oneline --decorate • git log -3 (display only the 3 most recent commits) • git log --after="2014-7-1“ (by date) • git log --author="John|Mary“ • git log --grep="JRA-228:“ (by name) • git log -S"Hello, World!" (by content)
  • 25. Useful links • Git clients – http://git-scm.com/downloads (required) – https://code.google.com/p/tortoisegit/wiki/Download • Useful Git resources – https://www.atlassian.com/git/tutorials/setting-up-a- repository/#!overview – http://ndpsoftware.com/git-cheatsheet.html#loc=workspace – https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf – Squash several Git commits into a single commit • Git books and docs – http://git-scm.com/book – Command’s list http://git-scm.com/docs – http://git-scm.com/documentation
  • 26. Home Work. Git 1. Work Cycle: 1. create and init remote repository (set-url); 2. checkout branch and create new one; 3. rename branch; 4. create new files and add it to git; 5. commit changes and push them to remote repo; 6. use reset command (stage, commit, etc.) 7. use stash command (list, drop, save, pop, branch) 2. Branches: 1. copy new branch from created before (task 1); 2. apply changes in new branch and commit it (create possible conflict between them); 3. merge changes in the second branch into first one.

Editor's Notes

  1. Remote rename - Rename the remote named <old> to <new>. All remote-tracking branches and configuration settings for the remote are updated. add - Adds a remote named <name> for the repository at <url>. rm - Remove the remote named <name>. All remote-tracking branches and configuration settings for the remote are removed. set-url – Changes URL remote points to. Sets first URL remote points to matching regex <oldurl> (first URL if no <oldurl> is given) to <newurl>. If <oldurl> doesn’t match any URL, error occurs and nothing is changed. i.e. git remote set-url origin git://new.url.here
  2. List of all main git commands http://git-scm.com/docs
  3. Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command. Stash command description - http://git-scm.com/book/en/Git-Tools-Stashing save - Save your local modifications to a new stash, and run git reset --hard to revert them.  branch - Creates and checks out a new branch named <branchname> starting from the commit at which the<stash> was originally created, applies the changes recorded in <stash> to the new working tree and index. list - List the stashes that you currently have. Each stash is listed with its name (e.g. stash@{0} is the latest stash, stash@{1} is the one before, etc.) show - Show the changes recorded in the stash as a diff between the stashed state and its original parent.  drop - Remove a single stashed state from the stash list. When no <stash> is given, it removes the latest one.  clear - Remove all the stashed states. Note that those states will then be subject to pruning, and may be impossible to recover.