Your SlideShare is downloading. ×
A Brief Introduction to Working with Git
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

A Brief Introduction to Working with Git

311
views

Published on

This slide deck is intended for Git beginners and focuses on the underlying concepts, the usage of the command line, especially the commands git reset, git checkout, git revert, git commit, and …

This slide deck is intended for Git beginners and focuses on the underlying concepts, the usage of the command line, especially the commands git reset, git checkout, git revert, git commit, and eventually introduces models for using Git and why git rebase may play an important role in some those models.

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
311
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Prehistory: Versioning was done manually (file was named main_v2.java)RCS and SCCS: text only, no central repository  only one developerCVS: allowed several developers to collaborate using a central repositorySVN: was getting famous because it was easier to use. But it „evangelized“ everyone on the „mainline development model“  no branching should be used.Bitkeeper: Made distributed versioning (P2P) famous and was used for Linux kernel development and several other agile open source projects.Git: Also distributed; it fostered branching because practically everything is a branch: if you check-out and start working, you just created a branch.
  • Transcript

    • 1. Business Informatics Group Institute of Software Technology and Interactive Systems Vienna University of Technology Favoritenstraße 9-11/188-3, 1040 Vienna, Austria phone: +43 (1) 58801-18804 (secretary), fax: +43 (1) 58801-18896 office@big.tuwien.ac.at, www.big.tuwien.ac.at A Brief Introduction to Working with Git 10.03.2014 VUT, Vienna, Austria Philip Langer
    • 2. History of Versioning Systems Based on http://codicesoftware.blogspot.com/2010/11/version-control- timeline.html local to central … central to distributed … 1972 sccs discourage branching … everything is a branch …
    • 3. Git: A Distributed Versioning System  There is no single repository server  Every peer is a full repository instance  Single-peer versioning possible  Including the complete history  Committing changes is independent of peers  Allows disconnected operation  Collaboration is done by pushing/pulling commits  Comparable to peer-to-peer networks  The role of peers is purely organizational  No technical difference among peers  Single common central server possible  One peer happens to be the central repo  But several other architectures are possible too  Gate-keeper architecture  Teams of teams 3 commit push & pull push & pull push & pull <Bob> <Alice> <Sally> <Server> <Harry> push & pull
    • 4. The Four Layers & Transferring Changes Among Them  Every repository consists of a  Workspace  Index (“staging area”)  Local repository  Remote repositories  …  Transferring changes  git add  workspace to index  git commit  index to local branch  git push  local branch to remote branch  …  Changes are organized in commits  Each commit has a parent  The history is basically a DAG 4
    • 5. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 5 default: HEAD default: --mixed History Index Workspace Head
    • 6. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 6 default: HEAD default: --mixed History Index Workspace Head
    • 7. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 7 default: HEAD default: --mixed History Index Workspace Head
    • 8. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard HEAD~  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 8 default: HEAD default: --mixed History Index Workspace Head
    • 9. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard HEAD~  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 9 default: HEAD default: --mixed History Index Workspace Head !
    • 10. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 10 default: HEAD default: --mixed History Index Workspace Head
    • 11. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 11 default: HEAD default: --mixed History Index Workspace Head Reset index after wrong add
    • 12. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed] HEAD~  History and index  git reset --soft  Only history  … 12 default: HEAD default: --mixed History Index Workspace Head
    • 13. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed] HEAD~  History and index  git reset --soft  Only history  … 13 default: HEAD default: --mixed History Index Workspace Head Undo last commit, however it‘s still there
    • 14. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft  Only history  … 14 default: HEAD default: --mixed History Index Workspace Head Does nothing actualy (HEAD is default)
    • 15. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft HEAD~  Only history  … 15 default: HEAD default: --mixed History Index Workspace Head
    • 16. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is HEAD?  A reference pointing to the last commit (of the current branch)  Thus, it will be the parent of the next commit  Relative commit expressions e.g. with HEAD~2  git reset [--soft | --mixed | --hard] [commit | reference to commit]  Resets HEAD in history, index, and/or workspace to [commit]  git reset --hard  History, index, and workspace  git reset [--mixed]  History and index  git reset --soft HEAD~  Only history  … 16 default: HEAD default: --mixed History Index Workspace Head Undo last commit, leaving index untouched
    • 17. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is checkout?  Get a version from the history  And overwrite workspace  (also for creating and changing branches … later)  git checkout -- <file/s>  Get version of <file/s> from HEAD  Overwrite version in workspace 17 History Index Workspace Head Undo last commit, leaving index untouched
    • 18. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is checkout?  Get a version from the history  And overwrite workspace  (also for creating and changing branches … later)  git checkout -- <file/s>  Get version of <file/s> from HEAD  Overwrite version in workspace 18 History Index Workspace Head Undo local changes to workspace. !
    • 19. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is revert?  Does not modify history (good if you pushed already)  Takes a commit from history  Creates reverse patch  Commits reverse patch (new commit)  git revert HEAD~1 19 History Index Workspace Head Must be clean!
    • 20. Before talking about branches… Demystifying “git reset”, “git checkout”, and “git revert”  What is revert?  Does not modify history (good if you pushed already)  Takes a commit from history  Creates reverse patch  Commits reverse patch (new commit)  git revert HEAD~1 20 History Index Workspace Head Undo commits after you‘ve already pushed them. Must be clean!
    • 21. Branching  After all every change (local or remote) is a fork leading to a new branch  So make branches a first-class concept  No logical difference between local and remote branches  Every merge is a branch merge 21 <Bob> <Server> <Alice>
    • 22. Branching  Each commit has a parent  A branch is nothing more than a pointer to a commit 22 Current Branch
    • 23. Branching  Each commit has a parent ( DAG)  A branch is nothing more than a pointer to a commit 23
    • 24. Branching  Local branches may link to “tracking branches” 24 Current Branch
    • 25. Branching  Branches can be linked in ./git/config (links are also created automatically in certain cases; or may be linked explicitly using git checkout --track) [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = https://code.google.com/a/eclipselabs.org/p/moliz/ [branch "master"] remote = origin merge = refs/heads/master [branch "issue_18_alf"] remote = origin merge = refs/heads/issue_18_alf 25
    • 26. Merging Branches  git checkout master git merge iss53 26
    • 27. Merging Branches  git checkout master git merge iss53 27 Note that git pull is a git fetch & git merge
    • 28. Branching Models of Git  Several different “models”  All entirely organizational  The svn-like model:  Only one branch  Only one central repo  git pull (origin master)  Apply changes  git commit (master)  git push (origin master)  Good for e.g. papers  The isolated-development model  Own branch for current dev  Own branch for releases  Own branch for each feature 28
    • 29. Keeping the History of Topic Branches Clean: Rebase  git checkout experiment … // apply changes git commit -a git checkout master git merge experiment 29
    • 30. Keeping the History of Topic Branches Clean: Rebase  git checkout experiment … // apply changes git commit -a git checkout master git merge experiment 30
    • 31. Keeping the History of Topic Branches Clean: Rebase  git checkout experiment … // apply changes git commit -a git rebase master 31Rebase is rewriting history! Never rebase pushed history!
    • 32. Keeping the History of Topic Branches Clean: Rebase  Improving previous commits … // apply changes git commit -a … // apply changes git commit -a git rebase -i HEAD~2 # Rebase 710f0f8..a5f4a0d onto 710f0f8 # # Commands: # p, pick = use commit # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit 32

    ×