Git Basics
Dionne Saunders
What Git isn’t…
Dionne Saunders
What Git isn’t…
Dionne Saunders
• The insult seen at least once every three pages in a Harry Potter novel.
What Git isn’t…
Dionne Saunders
• The insult seen at least once every three pages in a Harry Potter novel.
• Git is not a ...
So… what is Git?
Dionne Saunders
So… what is Git?
Dionne Saunders
• Backup
So… what is Git?
Dionne Saunders
• Backup
• Tracked Changes
So… what is Git?
Dionne Saunders
• Backup
• Tracked Changes
• Peace of mind
Git Branches
Dionne Saunders
Git Branches
Dionne Saunders
• Branches provide a means of isolating new code which is currently in
development or testing...
Git Branches
Dionne Saunders
• Branches provide a means of isolating new code which is currently in
development or testing...
Git Branches
Dionne Saunders
• Here’s an example of the benefit of branching, even when you’re coding solo:
Git Branches
Dionne Saunders
• Here’s an example of the benefit of branching, even when you’re coding solo:
Imagine for a ...
Git Branches
Dionne Saunders
• Here’s an example of the benefit of branching, even when you’re coding solo:
Imagine for a ...
Git Branches
Dionne Saunders
Let’s assume you did all that hard work on a separate branch called ‘relationships’.
Git Branches
Dionne Saunders
Let’s assume you did all that hard work on a separate branch called ‘relationships’.
You go b...
Git Branches
Dionne Saunders
Let’s assume you did all that hard work on a separate branch called ‘relationships’.
You go b...
Git Branches
Dionne Saunders
Let’s assume you did all that hard work on a separate branch called ‘relationships’.
You go b...
Create an account
Dionne Saunders
Create an account
Dionne Saunders
• Go to http://github.com and create an account
Create an account
Dionne Saunders
• Go to http://github.com and create an account
• Accounts are free, unless you want pri...
Cloning your repo
Dionne Saunders
Cloning your repo
Dionne Saunders
• Open a terminal (or “command prompt” for you windows peeps)
Cloning your repo
Dionne Saunders
• Open a terminal (or “command prompt” for you windows peeps)
• cd /somewhere
Cloning your repo
Dionne Saunders
• Open a terminal (or “command prompt” for you windows peeps)
• cd /somewhere
• git clon...
This is what the repository looks like
after creation via GitHub, then
cloning to your computer.
Basic Workflow
Dionne Saunders
Basic Workflow
Dionne Saunders
• It’s a matter of personal preference. I’ll show you a simple strategy I use to help
you g...
Branch off of ‘master’
Dionne Saunders
Branch off of ‘master’
Dionne Saunders
• The master branch is generally the source of truth. It reflects the current state...
Branch off of ‘master’
Dionne Saunders
• The master branch is generally the source of truth. It reflects the current state...
Branch off of ‘master’
Dionne Saunders
• The master branch is generally the source of truth. It reflects the current state...
Branch off of ‘master’
Dionne Saunders
• The master branch is generally the source of truth. It reflects the current state...
Branch off of ‘master’
Dionne Saunders
• The master branch is generally the source of truth. It reflects the current state...
Now that we’ve branched off, we see
our new local branch called ‘readme’.
Notice that there isn’t a
corresponding ‘origin’...
Pushing to origin
Dionne Saunders
Pushing to origin
Dionne Saunders
• To push your branch to the remote repository:
Pushing to origin
Dionne Saunders
• To push your branch to the remote repository:
• git push origin readme
Pushing to origin
Dionne Saunders
• To push your branch to the remote repository:
• git push origin readme
• In this comma...
Now that we’ve pushed to the
remote repository, we see that there
is a branch called origin/readme
Write some code, commit, and push
Dionne Saunders
Write some code, commit, and push
Dionne Saunders
• I have edited README.md and I want to push those changes to the remote...
Write some code, commit, and push
Dionne Saunders
• I have edited README.md and I want to push those changes to the remote...
Write some code, commit, and push
Dionne Saunders
• I have edited README.md and I want to push those changes to the remote...
Write some code, commit, and push
Dionne Saunders
• I have edited README.md and I want to push those changes to the remote...
Yay! We can now see that the
changes have been commited to our
local readme branch.
Pushing to origin… again
Dionne Saunders
Pushing to origin… again
Dionne Saunders
• To push your branch to the remote repository:
Pushing to origin… again
Dionne Saunders
• To push your branch to the remote repository:
• git push origin readme
Pushing to origin… again
Dionne Saunders
• To push your branch to the remote repository:
• git push origin readme
• In thi...
Our changes are now on
origin/readme
Merging back to master
Dionne Saunders
Merging back to master
Dionne Saunders
• We’re done with this feature. It’s ready to be merged back into master, there are...
Merging back to master
Dionne Saunders
• We’re done with this feature. It’s ready to be merged back into master, there are...
Merging back to master
Dionne Saunders
• We’re done with this feature. It’s ready to be merged back into master, there are...
Merging back to master
Dionne Saunders
• We’re done with this feature. It’s ready to be merged back into master, there are...
Merging back to master
Dionne Saunders
• We’re done with this feature. It’s ready to be merged back into master, there are...
Merging back to master
Dionne Saunders
Merging back to master
Dionne Saunders
• We have now ensured that the readme branch includes changes made to the
master br...
Merging back to master
Dionne Saunders
• We have now ensured that the readme branch includes changes made to the
master br...
Merging back to master
Dionne Saunders
• We have now ensured that the readme branch includes changes made to the
master br...
Merging back to master
Dionne Saunders
• We have now ensured that the readme branch includes changes made to the
master br...
Merging back to master
Dionne Saunders
Merging back to master
Dionne Saunders
• Master now has all the code we wrote in the readme branch. Let’s delete both
the ...
Merging back to master
Dionne Saunders
• Master now has all the code we wrote in the readme branch. Let’s delete both
the ...
Merging back to master
Dionne Saunders
• Master now has all the code we wrote in the readme branch. Let’s delete both
the ...
We only have a master branch
now, but we still have all the changes
that were made on the readme
branch.
What now?
Dionne Saunders
What now?
Dionne Saunders
• There are plenty of git resources on the internet. Here are a few examples:
What now?
Dionne Saunders
• There are plenty of git resources on the internet. Here are a few examples:
• http://stackover...
What now?
Dionne Saunders
• There are plenty of git resources on the internet. Here are a few examples:
• http://stackover...
What now?
Dionne Saunders
• There are plenty of git resources on the internet. Here are a few examples:
• http://stackover...
What now?
Dionne Saunders
• There are plenty of git resources on the internet. Here are a few examples:
• http://stackover...
What now?
Dionne Saunders
• There are plenty of git resources on the internet. Here are a few examples:
• http://stackover...
The End
Dionne Saunders
Visit http://ihacked.it to download this presentation.
Rails Girls Presentation - Basic Intro to Git & GitHub
Rails Girls Presentation - Basic Intro to Git & GitHub
Rails Girls Presentation - Basic Intro to Git & GitHub
Rails Girls Presentation - Basic Intro to Git & GitHub
Rails Girls Presentation - Basic Intro to Git & GitHub
Rails Girls Presentation - Basic Intro to Git & GitHub
Rails Girls Presentation - Basic Intro to Git & GitHub
Upcoming SlideShare
Loading in …5
×

Rails Girls Presentation - Basic Intro to Git & GitHub

600 views
534 views

Published on

A very basic introduction to Git & GitHub. Presented at Rails Girls Canberra

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
600
On SlideShare
0
From Embeds
0
Number of Embeds
139
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Rails Girls Presentation - Basic Intro to Git & GitHub

  1. 1. Git Basics Dionne Saunders
  2. 2. What Git isn’t… Dionne Saunders
  3. 3. What Git isn’t… Dionne Saunders • The insult seen at least once every three pages in a Harry Potter novel.
  4. 4. What Git isn’t… Dionne Saunders • The insult seen at least once every three pages in a Harry Potter novel. • Git is not a pre-requisite to writing code. You can accomplish everything covered in this workshop without any knowledge of Git.
  5. 5. So… what is Git? Dionne Saunders
  6. 6. So… what is Git? Dionne Saunders • Backup
  7. 7. So… what is Git? Dionne Saunders • Backup • Tracked Changes
  8. 8. So… what is Git? Dionne Saunders • Backup • Tracked Changes • Peace of mind
  9. 9. Git Branches Dionne Saunders
  10. 10. Git Branches Dionne Saunders • Branches provide a means of isolating new code which is currently in development or testing without affecting other branches, or the current working state of your application.
  11. 11. Git Branches Dionne Saunders • Branches provide a means of isolating new code which is currently in development or testing without affecting other branches, or the current working state of your application. This is useful for both individual, and collaborative development.
  12. 12. Git Branches Dionne Saunders • Here’s an example of the benefit of branching, even when you’re coding solo:
  13. 13. Git Branches Dionne Saunders • Here’s an example of the benefit of branching, even when you’re coding solo: Imagine for a moment that you are developing an app called Railsbook. You’re working on a new feature called ‘relationship statuses’. Part way through, someone reports a bug. Your users are no longer able to change the privacy settings of their profiles!
  14. 14. Git Branches Dionne Saunders • Here’s an example of the benefit of branching, even when you’re coding solo: Imagine for a moment that you are developing an app called Railsbook. You’re working on a new feature called ‘relationship statuses’. Part way through, someone reports a bug. Your users are no longer able to change the privacy settings of their profiles! You need to fix this fast, but you spent hours working on implementing ‘relationship statuses’. You don’t want to lose the work you’ve done for that, but it certainly isn’t ready to be deployed onto the server.
  15. 15. Git Branches Dionne Saunders Let’s assume you did all that hard work on a separate branch called ‘relationships’.
  16. 16. Git Branches Dionne Saunders Let’s assume you did all that hard work on a separate branch called ‘relationships’. You go back to the ‘master’ branch, create yet another branch called ‘privacy-fix’, and write some code to fix that bug.
  17. 17. Git Branches Dionne Saunders Let’s assume you did all that hard work on a separate branch called ‘relationships’. You go back to the ‘master’ branch, create yet another branch called ‘privacy-fix’, and write some code to fix that bug. When you’re done, you merge the ‘privacy-fix’ branch into the ‘master’ branch and deploy your code.
  18. 18. Git Branches Dionne Saunders Let’s assume you did all that hard work on a separate branch called ‘relationships’. You go back to the ‘master’ branch, create yet another branch called ‘privacy-fix’, and write some code to fix that bug. When you’re done, you merge the ‘privacy-fix’ branch into the ‘master’ branch and deploy your code. Now, you can switch back to the ‘relationships’ branch and continue to code this new feature.
  19. 19. Create an account Dionne Saunders
  20. 20. Create an account Dionne Saunders • Go to http://github.com and create an account
  21. 21. Create an account Dionne Saunders • Go to http://github.com and create an account • Accounts are free, unless you want private repositories
  22. 22. Cloning your repo Dionne Saunders
  23. 23. Cloning your repo Dionne Saunders • Open a terminal (or “command prompt” for you windows peeps)
  24. 24. Cloning your repo Dionne Saunders • Open a terminal (or “command prompt” for you windows peeps) • cd /somewhere
  25. 25. Cloning your repo Dionne Saunders • Open a terminal (or “command prompt” for you windows peeps) • cd /somewhere • git clone git@github.com:lenoretres/fakeapp.git #replace with correct URL
  26. 26. This is what the repository looks like after creation via GitHub, then cloning to your computer.
  27. 27. Basic Workflow Dionne Saunders
  28. 28. Basic Workflow Dionne Saunders • It’s a matter of personal preference. I’ll show you a simple strategy I use to help you get started.
  29. 29. Branch off of ‘master’ Dionne Saunders
  30. 30. Branch off of ‘master’ Dionne Saunders • The master branch is generally the source of truth. It reflects the current state of your deployed application.
  31. 31. Branch off of ‘master’ Dionne Saunders • The master branch is generally the source of truth. It reflects the current state of your deployed application. • Code which is not production ready shouldn’t be on your master branch.
  32. 32. Branch off of ‘master’ Dionne Saunders • The master branch is generally the source of truth. It reflects the current state of your deployed application. • Code which is not production ready shouldn’t be on your master branch. • To create a new branch:
  33. 33. Branch off of ‘master’ Dionne Saunders • The master branch is generally the source of truth. It reflects the current state of your deployed application. • Code which is not production ready shouldn’t be on your master branch. • To create a new branch: • git checkout –b feature
  34. 34. Branch off of ‘master’ Dionne Saunders • The master branch is generally the source of truth. It reflects the current state of your deployed application. • Code which is not production ready shouldn’t be on your master branch. • To create a new branch: • git checkout –b readme • In this command, we are essentially saying: git go to a new branch called readme
  35. 35. Now that we’ve branched off, we see our new local branch called ‘readme’. Notice that there isn’t a corresponding ‘origin’ branch. We have not yet pushed the branch to the remote repository.
  36. 36. Pushing to origin Dionne Saunders
  37. 37. Pushing to origin Dionne Saunders • To push your branch to the remote repository:
  38. 38. Pushing to origin Dionne Saunders • To push your branch to the remote repository: • git push origin readme
  39. 39. Pushing to origin Dionne Saunders • To push your branch to the remote repository: • git push origin readme • In this command, we are essentially saying: git upload my changes to a remote branch called readme
  40. 40. Now that we’ve pushed to the remote repository, we see that there is a branch called origin/readme
  41. 41. Write some code, commit, and push Dionne Saunders
  42. 42. Write some code, commit, and push Dionne Saunders • I have edited README.md and I want to push those changes to the remote repo
  43. 43. Write some code, commit, and push Dionne Saunders • I have edited README.md and I want to push those changes to the remote repo • First, I need to ‘commit’ the files locally:
  44. 44. Write some code, commit, and push Dionne Saunders • I have edited README.md and I want to push those changes to the remote repo • First, I need to ‘commit’ the files locally: • git commit –a –m ‘Modified readme to demonstrate a commit’
  45. 45. Write some code, commit, and push Dionne Saunders • I have edited README.md and I want to push those changes to the remote repo • First, I need to ‘commit’ the files locally: • git commit –a –m ‘Modified readme to demonstrate a commit’ • In this command, we are essentially saying: git commit all changed files with a message saying ‘Modified readme to demonstrate a commit’
  46. 46. Yay! We can now see that the changes have been commited to our local readme branch.
  47. 47. Pushing to origin… again Dionne Saunders
  48. 48. Pushing to origin… again Dionne Saunders • To push your branch to the remote repository:
  49. 49. Pushing to origin… again Dionne Saunders • To push your branch to the remote repository: • git push origin readme
  50. 50. Pushing to origin… again Dionne Saunders • To push your branch to the remote repository: • git push origin readme • In this command, we are essentially saying: git upload my changes to a remote branch called readme
  51. 51. Our changes are now on origin/readme
  52. 52. Merging back to master Dionne Saunders
  53. 53. Merging back to master Dionne Saunders • We’re done with this feature. It’s ready to be merged back into master, there are a couple of things we need to do for this: • git checkout master • git go to the branch called master
  54. 54. Merging back to master Dionne Saunders • We’re done with this feature. It’s ready to be merged back into master, there are a couple of things we need to do for this: • git checkout master • git go to the branch called master • git fetch • git are there any changes?
  55. 55. Merging back to master Dionne Saunders • We’re done with this feature. It’s ready to be merged back into master, there are a couple of things we need to do for this: • git checkout master • git go to the branch called master • git fetch • git are there any changes? • git pull origin master • git grab changes from the remote branch called master
  56. 56. Merging back to master Dionne Saunders • We’re done with this feature. It’s ready to be merged back into master, there are a couple of things we need to do for this: • git checkout master • git go to the branch called master • git fetch • git are there any changes? • git pull origin master • git grab changes from the remote branch called master • git checkout readme • git go to the branch called readme
  57. 57. Merging back to master Dionne Saunders • We’re done with this feature. It’s ready to be merged back into master, there are a couple of things we need to do for this: • git checkout master • git go to the branch called master • git fetch • git are there any changes? • git pull origin master • git grab changes from the remote branch called master • git checkout readme • git go to the branch called readme • git rebase master • git make sure this branch is on top of the branch called master
  58. 58. Merging back to master Dionne Saunders
  59. 59. Merging back to master Dionne Saunders • We have now ensured that the readme branch includes changes made to the master branch while we were off doing our own thing.
  60. 60. Merging back to master Dionne Saunders • We have now ensured that the readme branch includes changes made to the master branch while we were off doing our own thing. • We’re ready to merge the branch into master
  61. 61. Merging back to master Dionne Saunders • We have now ensured that the readme branch includes changes made to the master branch while we were off doing our own thing. • We’re ready to merge the branch into master • git checkout master • git go to the branch called master
  62. 62. Merging back to master Dionne Saunders • We have now ensured that the readme branch includes changes made to the master branch while we were off doing our own thing. • We’re ready to merge the branch into master • git checkout master • git go to the branch called master • git merge readme • git merge the changes from readme into the current branch (master)
  63. 63. Merging back to master Dionne Saunders
  64. 64. Merging back to master Dionne Saunders • Master now has all the code we wrote in the readme branch. Let’s delete both the local and remote readme branches:
  65. 65. Merging back to master Dionne Saunders • Master now has all the code we wrote in the readme branch. Let’s delete both the local and remote readme branches: • git –d readme • git delete the branch called readme
  66. 66. Merging back to master Dionne Saunders • Master now has all the code we wrote in the readme branch. Let’s delete both the local and remote readme branches: • git –d readme • git delete the branch called readme • git push origin :readme • This command is non-intuitive and weird. What it’s doing is deleting the remote branch. The colon is necessary. Don’t ask me why they did it this way =)
  67. 67. We only have a master branch now, but we still have all the changes that were made on the readme branch.
  68. 68. What now? Dionne Saunders
  69. 69. What now? Dionne Saunders • There are plenty of git resources on the internet. Here are a few examples:
  70. 70. What now? Dionne Saunders • There are plenty of git resources on the internet. Here are a few examples: • http://stackoverflow.com is a Q&A site, if you’re feeling a bit lost with git or coding this is a great resource to check out.
  71. 71. What now? Dionne Saunders • There are plenty of git resources on the internet. Here are a few examples: • http://stackoverflow.com is a Q&A site, if you’re feeling a bit lost with git or coding this is a great resource to check out. • http://try.github.io is an interactive tutorial courtesy of GitHub & CodeSchool. You can try git commands online completely risk free.
  72. 72. What now? Dionne Saunders • There are plenty of git resources on the internet. Here are a few examples: • http://stackoverflow.com is a Q&A site, if you’re feeling a bit lost with git or coding this is a great resource to check out. • http://try.github.io is an interactive tutorial courtesy of GitHub & CodeSchool. You can try git commands online completely risk free. • http://gitweekly.com/gitcasts is a git tutorial site.
  73. 73. What now? Dionne Saunders • There are plenty of git resources on the internet. Here are a few examples: • http://stackoverflow.com is a Q&A site, if you’re feeling a bit lost with git or coding this is a great resource to check out. • http://try.github.io is an interactive tutorial courtesy of GitHub & CodeSchool. You can try git commands online completely risk free. • http://gitweekly.com/gitcasts is a git tutorial site. • Go to GitHub, find an open source project, and make a code contribution.
  74. 74. What now? Dionne Saunders • There are plenty of git resources on the internet. Here are a few examples: • http://stackoverflow.com is a Q&A site, if you’re feeling a bit lost with git or coding this is a great resource to check out. • http://try.github.io is an interactive tutorial courtesy of GitHub & CodeSchool. You can try git commands online completely risk free. • http://gitweekly.com/gitcasts is a git tutorial site. • Go to GitHub, find an open source project, and make a code contribution. • Open source contributions are a great way of giving back to the community, and showing off your code kung-fu to potential employers. Most of the gems you will end up using are open source projects.
  75. 75. The End Dionne Saunders Visit http://ihacked.it to download this presentation.

×