Git intro hands on windows with msysgit

871 views
810 views

Published on

Git intro hands on windows with msysgit step by step

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

No Downloads
Views
Total views
871
On SlideShare
0
From Embeds
0
Number of Embeds
112
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Git intro hands on windows with msysgit

  1. 1. GIT Intro and usage onWindows - BasicBy Geshan Manandharhttp://geshan.blogspot.com1http://geshan.blogspot.com
  2. 2. Agenda What is git Who uses it, features How to use git on windows Prepare working directory Create public repository Add, commit, pull, push Git ignore Other commands and things to look athttp://geshan.blogspot.com 2
  3. 3. GIT is a free & open source, distributedversion control system. designed to handle everything from smallto very large projects with speed andefficiency. a developer’s friend in a multideveloper environment. a must tool to go back in history to whatyou coded and see the code changesmade in the timeline.3http://geshan.blogspot.com
  4. 4. Who uses GIT Many big names including◦ Linux/Kernel◦ Eclipse◦ Ruby on Rails◦ Android◦ PostgreSQL◦ Git itself.4http://geshan.blogspot.com
  5. 5. Why use Git/ Features Fast Distributed (no central repository) Can work offline Small (file system usage) Has a staging area Access control (with gitosis) Fit for any project size Branching, tags … GitHub.com◦ Reference: http://whygitisbetterthanx.com5http://geshan.blogspot.com
  6. 6. Distributed?? No Centralrepository All developershave a workingcopy and ownprivate repo (.git) Code transfershould be done onnon-private repo.http://geshan.blogspot.com 6Image Source:http://coding.smashingmagazine.com/2011/07/26/modern-version-control-with-git-series/
  7. 7. How to use on windows? Could not find mature GUI tools liketortoise SVN. Integrated in Eclipse (with plugin) andNetBeans (good colorful support). If you are programmer, you are notscared of the command line so: Download MsysGit :http://code.google.com/p/msysgit/downloads/listhttp://geshan.blogspot.com 7
  8. 8. MsysGit for git on Windowshttp://geshan.blogspot.com 8Steps:1. Download the exe file (or the portable one, it will not needinstallation).2. Install msysgit , next … next is your friend here with finish – noneed of any fancy configuration.3. Run the git bash application.
  9. 9. Git bash part of MsysGithttp://geshan.blogspot.com 9
  10. 10. User and line settings for win If you are familiar with ~ of unix systemsthis might be easy. Make sure where your home dir is inyour windows setup like:◦ /c/users/Geshan – for me in Windows 7 Set ~/.bash_profile if you want.(googlebash profiles and dot files, if you want to) Run this: git config --global core.autocrlf true Have a look for new line setting if need be:http://github.com/guides/dealing-with-newlines-in-githttp://geshan.blogspot.com 10
  11. 11. Introduce yourself to GIT execute commands in bash◦ git config --global user.name <name>◦ git config --global user.email <email>◦ (this gets written to your ~/.gitconfig file) Example◦ git config --global user.name “GeshanManadhar”◦ git config --global user.email“me@somedomain.com”http://geshan.blogspot.com 11
  12. 12. Some conceptual clarity You have a working directory and yourprivate repo (a .git folder in your dir) You always push your changes andpull changes from another non-privaterepository.http://geshan.blogspot.com 12Working Dir with gitPublic git repo on file system
  13. 13. Preparing your working dirhttp://geshan.blogspot.com 13Nothing significant just created a directory with a file that’s it.
  14. 14. Preparing working dir 2http://geshan.blogspot.com 14
  15. 15. Working directory made Commands used◦ git init ; to initialize the current dir for gittracking.◦ git status; shows current status◦ git add; put files to stating area Variations like Git add . ; . Is for all changed files Git add /path/to/file ; /c/dir1/file1.txt Git add /path/a.* etchttp://geshan.blogspot.com 15
  16. 16. First commithttp://geshan.blogspot.com 16git commit –m “message”;Files have been put into the local repository (the .git dircreated with git init)All things are in local so we need to push things to a non-private repository. For this example I’ll create a localrepository.Always remember to write concise but meaningfulcommit messages.
  17. 17. Creating public repositoryhttp://geshan.blogspot.com 17A bare passive public repo has been created for pushing code.Remember the path is /c/users/geshan/gitrepos/testgit.gitDifferent command : git init --bare;Now we will link the working directory with this public repo.
  18. 18. Linking working dir with publicrepohttp://geshan.blogspot.com 18Remote repository created in previous slide linked to the working directory.git remote add <name> <path>Path can be:File : /home/geshan/gitrepost/testrepo.gitRemote file: ssh://user1@domain1.com/home/user1/gitrepos/test.gitGitosis: git@domain1.com:test.git
  19. 19. First push to remote repo git push <repo_name><branch_name> Repo_name is just a alias to the path. git push origin master◦ Default repo when cloned in origin anddefault branch is master.http://geshan.blogspot.com 19
  20. 20. First pull attempt Pull is done to get the changes doneby others in the self working directory. git pull <repo_name> <branch_name> git pull origin masterhttp://geshan.blogspot.com 20
  21. 21. .gitignore file .gitignore file is generally placed in theroot of the working directory. As the name suggests it can ignorecertain files from git. Generally local config is ignored but aback up is kept for others, exampledatabase username password config.http://geshan.blogspot.com 21
  22. 22. Using .gitignorehttp://geshan.blogspot.com 22Scenario:Local databasesettings arestored indatabase.phpfile
  23. 23. Continue to push bkp filehttp://geshan.blogspot.com 23
  24. 24. Pull by a new developerhttp://geshan.blogspot.com 24A newdeveloperwillgenerallyclone theproject,thancreatenew files.-Noticegit remote–vGit branchshowsavailablebranches.
  25. 25. Scenario dev 2 posts code Dev 2 changed test.txt and pushed hiscode to public repo.http://geshan.blogspot.com 25
  26. 26. Dev 1 pulled the changes. Dev 1 can immediately have thechanged code.http://geshan.blogspot.com 26
  27. 27. Gitk to know what changed execute gitk on a git repo root to getthis.http://geshan.blogspot.com 27
  28. 28. Other git commands git log git short log –sne git checkout / git branch –b newbranch git tag v 1.0 –a “test” git fsck git push dev feature1; - testing you.http://geshan.blogspot.com 28
  29. 29. Things to look at Reset the code to old version Branching with git Tagging with git How to handle conflict situation Other git features and commands Check out the git cheat sheet:http://www.cheat-sheets.org/saved-copy/git-cheat-sheet.pdf For details of hashing etc check the gitinternals book.http://geshan.blogspot.com 29
  30. 30. Happy Git-ing Google git See videos on youtube Find some good podcasts on git You will like what you usehttp://geshan.blogspot.com 30

×