Git On Windows Plain Introduction


Published on

Plain Introduction to Git On Windows
install msysgit, configure git, make your first repository and commit, look at objects and learn more

Published in: Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Git On Windows Plain Introduction

  1. 1. Git On Windows Plain Introduction for testers; and you? marekj | helping testers adopt watir
  2. 2. why this plain introduction? <ul><li>You are a software tester </li></ul><ul><ul><li>you work mainly on windows </li></ul></ul><ul><ul><li>you have heard about git </li></ul></ul><ul><ul><li>you want to experiment </li></ul></ul><ul><ul><li>you need some tools from github that you can use on your job (like watircraft or watirloo ) </li></ul></ul><ul><ul><li>or you are curious how to get you mind around this git thing everyone is talking about... </li></ul></ul><ul><ul><li>ok, let's get started. </li></ul></ul>
  3. 3. Roadmap <ul><li>In this presentation we will: </li></ul><ul><ul><li>install msysgit (the git for windows) </li></ul></ul><ul><ul><li>tell git who you are </li></ul></ul><ul><ul><li>tell git you are on windows </li></ul></ul><ul><ul><li>init first git repository </li></ul></ul><ul><ul><li>look at 3 git spaces and 4 git objects </li></ul></ul><ul><ul><li>and send you to git community book </li></ul></ul><ul><ul><ul><li> </li></ul></ul></ul>
  4. 4. Download msysgit <ul><li>get msysgit exe file from here: </li></ul><ul><ul><ul><li> </li></ul></ul></ul><ul><ul><ul><li>(probably Git-1.6.1-preview20081227.exe) </li></ul></ul></ul><ul><li>No, we don't want the cygwin version, we want msysgit for sure. </li></ul><ul><ul><ul><li>Please now take the time to appreciate the guys who wrote and maintain git and msysgit. I am sure they will appreciate it. </li></ul></ul></ul>
  5. 5. install msysgit <ul><li>Double click exe file to start </li></ul><ul><ul><li>install to default location or c:programsgit (my preferred place) </li></ul></ul><ul><ul><li>select checkboxes for 'git bash here' and 'git gui here' windows explorer integration (yes, you want it). </li></ul></ul><ul><ul><li>select radio 'git bash only' (don't worry about other options for now). </li></ul></ul><ul><ul><li>select 'Use OpenSSH'. (built into git). </li></ul></ul>
  6. 6. Folder or Directory <ul><li>Folder is what Windows calls directory. In Unix there is no 'folder' concept. There are only files. In Unix everything is a file, even a directory is a file that contains other files. </li></ul><ul><li>This important distinction will be used in git so make a note of it. </li></ul>
  7. 7. About home directory <ul><li>(skip this if you understand Unix and &quot;~&quot;) </li></ul><ul><ul><li>on windows your home folder is known as &quot;%USERPROFILE%&quot; that system expands to proper path visible to you </li></ul></ul><ul><ul><ul><li>c:Documents and Settings<name> on Win XP or c:Users<name> on Vista </li></ul></ul></ul><ul><li>git refers to this as &quot;~&quot; directory </li></ul><ul><ul><li>&quot;~&quot; (tilda) a unix notiation that expands to home path </li></ul></ul>
  8. 8. Make new folder and open git bash here <ul><li>In Windows Explorer open your home folder and make a new folder 'testgit' </li></ul><ul><li>right click on </li></ul><ul><li>testgit and click </li></ul><ul><li>'git bash here' </li></ul><ul><li>to open git => </li></ul>
  9. 9. git bash here <ul><li>and now your command window shows something like this. This is not git yet. this is bash prompt </li></ul><ul><li>learn more: </li></ul>
  10. 10. ~/.bash_profile <ul><li>When git bash starts it reads settings in your &quot;~/.bash_profile&quot; file if you have one set up to customize your bash session </li></ul><ul><li>learn more: google for &quot;.bash_profile&quot; or search for dotfiles repositories and borrow settings from other people. </li></ul>
  11. 11. gitconfig and ~/.gitconfig <ul><li>gitconfig: global settings </li></ul><ul><ul><li>look at: Programs/Git/etc/gitconfig </li></ul></ul><ul><ul><ul><li>notice the setting &quot;autocrlf = true&quot; (later on this) </li></ul></ul></ul><ul><ul><ul><li>examine other files: motd and git-completion.bash. we'll talk about that too later </li></ul></ul></ul><ul><li>~/.gitconfig: user settings file </li></ul><ul><ul><li>tell git about yourself and your machine first and your preferences to create this file. </li></ul></ul><ul><ul><li>Learn more: </li></ul></ul><ul><ul><li> </li></ul></ul>
  12. 12. LF and CRLF line endings <ul><li>Git knows you are on Windows. </li></ul><ul><ul><li>&quot;autocrlf = true&quot; in git/etc/gitconfig </li></ul></ul><ul><li>CRLF is for Windows and LF is for unix. </li></ul><ul><ul><li>to keep cross platform development going smooth keep CRLF for windows and LF for unix </li></ul></ul><ul><ul><li>with autocrlf = true git converts your windows CRLF into LF internally </li></ul></ul><ul><li>learn more: </li></ul><ul><ul><li> </li></ul></ul>
  13. 13. Introduce yourself to git <ul><li>execute commands in bash </li></ul><ul><ul><li>git config --global <name> </li></ul></ul><ul><ul><li>git config --global <email> </li></ul></ul><ul><ul><li>(this gets written to your ~/.gitconfig file) </li></ul></ul>
  14. 14. git going with git init <ul><ul><li>so you are in bash, yes? </li></ul></ul><ul><ul><li>and you are in &quot;testgit&quot; directory, yes? </li></ul></ul><ul><ul><li>ok, let's initialize a new repository with &quot;git init&quot; </li></ul></ul><ul><ul><li>what happened? </li></ul></ul><ul><ul><li>git created a .git </li></ul></ul><ul><ul><li>directory </li></ul></ul><ul><ul><li>take a look => </li></ul></ul>
  15. 15. git and 3 conceptual spaces <ul><li>Git deals with 3 spaces. Each space is a self contained area of concern to git and to you. </li></ul><ul><ul><li>Working Directory (our 'testgit' folder) </li></ul></ul><ul><ul><ul><li>this is where you keep your current files visible in directory or folder. </li></ul></ul></ul><ul><ul><li>Index or Stage (&quot;testgit/.git/index&quot;) </li></ul></ul><ul><ul><ul><li>this is where git keeps snapshot to be committed permanently to Repository </li></ul></ul></ul><ul><ul><li>Repository (&quot;testgit/.git/objects/*&quot;) </li></ul></ul><ul><ul><ul><li>This is the history of commits, trees, blobs etc.. </li></ul></ul></ul>
  16. 16. git going with a new file <ul><li>Create ~/testgit/README.txt file </li></ul><ul><ul><li>open the file and type 'hello git' and save it. </li></ul></ul><ul><li>ask git about status </li></ul>
  17. 17. working directory changes <ul><li>git status scans your 'working directory' (1st area of concern to you) and reports to you what changed from a last known snapshot (either in Index or Repository) </li></ul><ul><li>in this case we have a brand new file README.txt but git will not track it unless we tell it explicitly to do so with 'git add' command </li></ul>
  18. 18. ask git to track changes <ul><li>when you tell git to 'add' file to be tracked you ask it to add it to its 'index' or 'stage' area (the second area of concern for you) </li></ul><ul><ul><li>imagine you put the file on a stage in a spotlight so that every one of its moves is tracked by git. (a bit of Hollywood metaphor here might help) </li></ul></ul>
  19. 19. git add . (or current dir) <ul><li>a dot &quot;.&quot; in unix and windows means 'current directory' (fyi: the two dots &quot;..&quot; means parent directory) </li></ul><ul><li>execute </li></ul><ul><li>&quot;git add .&quot; </li></ul><ul><li>and check </li></ul><ul><li>status => </li></ul>
  20. 20. what happened? <ul><li>you just told git to scan current Working Directory and make a snapshot (photo) of how things look and put in 'Index&quot; </li></ul><ul><ul><li>git stores the snapshot in the 'stage' or 'index' area (yes, that second area) </li></ul></ul><ul><ul><li>if you were to modify README.txt at this time git will not have those changes in its index or stage. you would have to make a new 'photo' </li></ul></ul>
  21. 21. git commit -m 'message' <ul><li>record the 'stage' area permanently with git commit -m 'and message' </li></ul><ul><li>it goes to 3rd area of concern (Repository) </li></ul><ul><li>notice git tells you it created d712f52 </li></ul><ul><li>we'll look at </li></ul><ul><li>that </li></ul><ul><li>later => </li></ul>
  22. 22. look at git log <ul><li>Now that you made your first commit let's take a look at the log with &quot;git log -p&quot; </li></ul><ul><li>notice the strange commit number bd71252..blablablabla </li></ul><ul><li>and a unified diff format of your file changes </li></ul>
  23. 23. git hash key known as SHA <ul><li>What is this 'SHA' thing? </li></ul><ul><ul><li>the commit number is a 40 characters long Secure Hash Algorithm 'object name' or SHA for short. </li></ul></ul><ul><ul><li>Learn More </li></ul></ul><ul><li> </li></ul>
  24. 24. git objects <ul><li>There are 3 objects we want care about at this time. (Objects in Repository) </li></ul><ul><ul><li>COMMIT object (point in time to tree) </li></ul></ul><ul><ul><li>TREE object (point to dir and files) </li></ul></ul><ul><ul><li>BLOB object (file contents) </li></ul></ul><ul><ul><li>4th object TAG we'll deal with later </li></ul></ul><ul><li>Every object is identified with SHA, a 40 char long key </li></ul>
  25. 25. example of 3 git objects <ul><li>in our example </li></ul><ul><li>commit object </li></ul><ul><li>points to </li></ul><ul><li>Tree object </li></ul><ul><li>which points to </li></ul><ul><li>Blob object </li></ul><ul><li>(you don't need all 40 chars) </li></ul>
  26. 26. Learn More <ul><li>Well. I think the next step is to read guides and books online. </li></ul><ul><li>start with the git community book </li></ul><ul><li> </li></ul>
  27. 27. Extra. Configure Git Prompt <ul><li>copy programs/git/etc/git-completion.bash file to </li></ul><ul><li>~/.git-completion.bash file </li></ul><ul><li>in file ~/.bashrc enter the following line </li></ul><ul><li>source ~/ </li></ul><ul><li>in file ~/.bash_profile set this line to make your prompt: PS1='e[32mpwd:e[31;1m W$(__git_ps1 &quot; (%s)&quot;) $ e[0m ' </li></ul><ul><li>Notice the git branch name in your prompt => (this one is Watir branch) </li></ul>
  28. 28. Thank you next we'll do github, ok? marekj | web browser automation with watir