Github basics

8,584 views
8,402 views

Published on

A company training for the ba

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,584
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
173
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Github basics

  1. 1. GIT & GITHUB BASICSGameCraft Training Radoslav Georgiev (@Rado_G)
  2. 2. DISCLAIMERI’m not a Git expert or pro 
  3. 3. Agenda• Why use Source Control System ?• How to setup Git and Github on Windows ?• Terminology• Repositories 1.0 – git {init, add, commit, push, remote}• Repositories 2.0 – .gitignore, git {clone, pull, revert, mv, rm}• Fork & Pull + Shared Repos
  4. 4. Why use Source Control Systems ? What is ? Why use ?• SCS are a tool that helps • Keeps the developing keeping versions of the process simple code • All files are hosted• SCS allow multiple (Github) developers to work on the • No nose bleed! same code with minimum • Tons of благинки amount of collisions
  5. 5. No Source Control System =
  6. 6. Agenda• Why use Source Control System ?• How to setup Git and Github on Windows ?• Terminology• Repositories 1.0 – git {init, add, commit, push, remote}• Repositories 2.0 – .gitignore, git {clone, pull, revert, mv, rm}• Fork & Pull + Shared Repos
  7. 7. How to setup Git and Github onWindows?• First of all – create a Github Account• And second :• There’s a great guide @ the Github site - http://help.github.com/win-set-up-git/
  8. 8. How to setup Git and Github onWindows? cont’d• You’ll need msysgit (Linux shell)• You’ll have to generate an SSH key-pair • And think of a passphrase ! <- Important• You’ll have to add the SHH keys to your Github account• Then test : $ ssh –T git@github.com some output .. (yes/no) $ yes Hi username! You‟ve successfully authenticated, but Github does not provide shell access.• gg, wp
  9. 9. And some configuration ^_^• Name & Email – Github tracks them$ git config –global user.name “Firstname Lastname”$ git config –global user.email “email@email.com”• Github API token • On the GitHub site Click “Account Settings” > Click “Account Admin.”$ git config –global github.user username$ git config –global github.token the_token
  10. 10. DEMO TIME1) Create a Github account2) Set up with Windows
  11. 11. Agenda• Why use Source Control System ?• How to setup Git and Github on Windows ?• Terminology• Repositories 1.0 – git {init, add, commit, push, remote}• Repositories 2.0 – .gitignore, git {clone, pull, revert, mv, rm}• Fork & Pull + Shared Repos
  12. 12. Some basic Terminology• git = the shell command to work with Git• repo = Repository, where the code for a given project is kept• commit = verb, means push the code to the server (in Git, commit = (commit + push)• diff = the difference between two versions of a file• SSH = Secure SHell – Network protocol for communication between machines• RSA = Rivest, Shamir, Adleman – public-key cryptography algorithm $ command Output of the command
  13. 13. Agenda• Why use Source Control System ?• How to setup Git and Github on Windows ?• Terminology• Repositories 1.0 – git {init, add, commit, push, remote}• Repositories 2.0 – .gitignore, git {clone, pull, revert, mv, rm}• Fork & Pull + Shared Repos
  14. 14. Lets create a repo !• Click on the new repository button in Github• Start the shell (Git Bash)• Execute the super-complex command : $ git init Initialized empty Git repository in c:/code/TestingGithub/.git/• Great, now we have repo. Lets create a file, shall we ? $ touch omgrofl.txt $ notepad omgrofl.txt (and add text) or $ echo “rofllol” > omgrofl.txt $ cat omgrofl.txt  cat prints to the output rofllol
  15. 15. Lets create a repo ! (cont’d)• Okay, lets add it ! $ git add omgrofl.txt• And commit it  $ git commit –m „This is a commit message‟ Some gitorish output• And for the sake of learning, lets edit it again $ echo “roflcopter” >> omgrofl.txt $ cat omgrofl.txt rofllol roflcopter
  16. 16. Lets create a repo ! (cont’d)• And now, lets see : $ git status• Outputs : # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: omgrofl.txt• Almost there $ git add omgrofl.txt $ git status
  17. 17. How it works? Staging area.
  18. 18. What about Github ? Remotes ?• Okay, you suck, there’s nothing @ Github• Damn. Enter magic! $ git remote add origin git@github.com:UserName/ProjectName.git• Git commits locally, pushes remotely !!!!!!!• Add the remote when the repo is created (git init, remember ? ) $ git remote add [name] [url]• Want to see the remotes ? $ git remote -v
  19. 19. What about Github ? Push it up, baby!• Okay, we have committed and added a remote to Github. It’s time to push  $ git push origin master Enter passphrase ! • Open up the repo in Github and enjoy ^_^• The push command explained : $ git push [remote_name] [branch]• Branches are black magic for later • There’s a big chance that the branch you are pushing to will be named “master”
  20. 20. Recap ! Creating a repo• Create a repo $ git init• Add an remote $ git remote add origin git@github.com:UserName/ProjectName.git• Check if directory is a git repo $ ls –la Search for .git folder
  21. 21. Recap ! The workflow.• Edit files and check the status $ git status• Add them to the staging area $ git add file1.php file2.php file3.php• Commit the changes $ git commit –m „Commit message that explains the changes‟• Push them to Github $ git push origin master Enter passphrase!• Celebrate ! 
  22. 22. DEMO1) Create yourself a repo (from Github)2) Add and Commit few files3) Push them !4) Repeat 2) and 3) few times
  23. 23. TAKE A BREAK.We all deserve it 
  24. 24. Agenda• Why use Source Control System ?• How to setup Git and Github on Windows ?• Terminology• Repositories 1.0 – git {init, add, commit, push, remote}• Repositories 2.0 – .gitignore, git {clone, pull, revert, mv, rm}• Fork & Pull + Shared Repos
  25. 25. Don’t push your passwords• Use .gitignore $ touch .gitignore $ echo “db_config.php” >> .gitignore $ git add .gitignore $ git push origin master Enter passphrase!• Something missing ? $ git commit –m „You are not seeing my passwords!‟
  26. 26. Made a mistake ? No worries• Unstage something – git reset$ git add index.php$ git statusSays it‟s staged. I don‟t want to ! I changed my mind.$ git reset HEAD – index.php$ git statusNow I‟m happy ^_^• Revert a commit ? Reset hard! $ git reset –hard HEAD~1 OR $ git reset –hard <commit_id>
  27. 27. Fork time.• If you want to get a repo – fork is the way.• Fork on github and then $ git clone git@github.com:UserName/ProjectName.git• This inits a new Git repository!• You can do everything with the code now – this is a separate repository.• More @ http://help.github.com/fork-a-repo/
  28. 28. Shared repos• If you are added as a collaborator @ some repo – you can do everything (clone, add, commit, push) without restrictions.• Shared repos mean more developers. More Developers = more changes. $ git pull [remote_name]• This will pull the latest changes 

×