Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What is Git?

What is Git?

Baby don't hurt me / don't hurt me / no more

B8d45998626d3dd3c582c4aeee792e2d?s=128

Andrew Best

June 30, 2015
Tweet

Transcript

  1. What is Git Baby don’t hurt me / don’t hurt

    me / no more
  2. Page So, what is Git? › Git is an application

    that provides Distributed Source Control. › It provides features similar to TFS in that it allows us to version control our code, tag these versions with metadata, stash, branch, merge, and a bunch of other bits and bobs. › The windows version is called msysgit (https://msysgit.github.io/) › Git can be used from either a command line interface (CLI), or from a few GUI-driven applications, such as GitExtensions (https://code.google.com/p/gitextensions/) / Copyright ©2014 by Readify Pty Ltd 2
  3. Page Distributed Source Control › TFS is centralized, Git is

    distributed. › With TFS, when you create a workspace mapping from a repository to your PC and retrieve the code, you are retrieving a snapshot of the latest version of the code from the TFS server. › With Git, when you Clone a repository, you retrieve the entire repository from the nominated Origin, including all history. › This means with git that once you Clone a repository, you have a complete working backup of the Origin. › Once you have Clonedyou can then work completely offline with the repository until you decide you want to sync with Origin. / Copyright ©2014 by Readify Pty Ltd 3
  4. Page Local vs Remote › Work locally, synchronize remotely. ›

    Local commands: add, commit, branch. › These commands let you modify your local git repository while you work. › Remote commands: pull, fetch, push. › These commands let you interact with your remote repository and synchronize your work. / Copyright ©2014 by Readify Pty Ltd 4
  5. Page Working locally / Copyright ©2014 by Readify Pty Ltd

    5 When working locally, files are in one of three states: committed, modified, or staged. Committed files are stored safely in your local .git database. Modified files are files in your working directory you have changed but not yet staged or committed. Staged files are modified files that have been marked to be added to your next commit.
  6. Page Staging visualised / Copyright ©2014 by Readify Pty Ltd

    6
  7. Page How do I use it? › Lets assume we

    have a local repository cloned and we are ready to write some code. › First, create a branch with git checkout –b “branchname”. This will keep our changes isolated from Master until they have been reviewed in a PR. › Now code away! › When you have satisfied your need to code, you can see what changes you have made with git statusor git log. Or just jump into GitExt › When you are ready to ‘check in’ your code, you can use git add –Ato “stage” all of your changes. › Once you are happy with your staged changes, commit them locally with git commit –m “Commit message” / Copyright ©2014 by Readify Pty Ltd 7
  8. Page Push, pull, fetch! › Once you have been working

    for a little while you may want to integrate any changes in the master branch with your work. › You have a couple of options! Pull, or fetch. › When you pull, changes from the remote branch you pull from (Master in this case) will be merged directly into your local workspace, and you may have to resolve changes. › When you fetch, you pull the changes down into your git repository, but the working area is not updated. You can then then optionally merge those changes into your branch if you wish. › Once you have finished merging, Push your changes up! / Copyright ©2014 by Readify Pty Ltd 8
  9. Page Under the hood › Git works in such a

    way that you only ever have a single copy of the code in your working directory. › Commits store a snapshot (not a diff) of the file changes you have made in the git database, along with a reference to the previous commit. › Commits therefore end up forming a “directed acyclic graph” › When you check out a commit your working directory is rebuiltbased on the tree of commits from the one you have checked out. › This means when we branch, we still only have a single copy of the source locally, we don’t need separate folders for separate branches. › When we check out a different branch, git will rebuild our working directory based on the tree of commits cascading down from that branch. / Copyright ©2014 by Readify Pty Ltd 9
  10. Page Branching › Branching in Git is a lightweight operation,

    as branches are just pointers to a commit. › A branch therefore is just a reference to a commit. › Branches come in a couple of flavours: local and remote. Local branches are those on our machine that point to commits on our local repository. › Remote branches are of the form origin/{branch}, and they let us track the state of our remote repo. Git automatically updates them every time we communicate with our remote for some reason. / Copyright ©2014 by Readify Pty Ltd 10
  11. Page Branching workflow › With Git you are always working

    in a branch.They are non-optional. › The central branch or ‘trunk’ is referred to as master. Masteris the default branch created when the repository is initialized. When working you branchfrom master, and when done you mergeback into master. / Copyright ©2014 by Readify Pty Ltd 11
  12. Page Glossary › Clone: akin to establishing a workspace mapping

    and pulling down the code in TFS, cloneretrieves an entire repository for us. › Pull: akin to “Get Latest” in TFS, pull retrieves the latest changesetsfrom our upstream Remote repository and attempts to merge them in with our current work. › Fetch: similar to pull, this retrieves the latest changesetsfrom our upstream Remote repository, but does not attempt to merge them in with our current work. › Add: add marks files that you have changed as ready to commit. Only the files marked by ‘add’ will then be committed on your next commit. Other modified files will not be committed. › Commit: saves the work you have staged into the git repository. › Push: akin to ‘check in’ in TFS, this pushes any changes you have made locally up to the remote repository. If it has changes that you haven’t yet pulled down and integrated, this will fail. / Copyright ©2014 by Readify Pty Ltd 12
  13. Page Further learnings › http://think-like-a-git.net/ (How git uses graphs to

    track changes, and how we can use them to make our lives easier) › http://rogerdudler.github.io/git-guide/ (A nice brief guide to working with git) › http://jake.ginnivan.net/explain-git-with-d3/ (A sandbox for playing with git concepts) / Copyright ©2014 by Readify Pty Ltd 13