Git intro hands on windows with msysgit


Published on

Git intro hands on windows with msysgit step by step

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
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.com1
  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 at 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.3
  4. 4. Who uses GIT Many big names including◦ Linux/Kernel◦ Eclipse◦ Ruby on Rails◦ Android◦ PostgreSQL◦ Git itself.4
  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 …◦ Reference: http://whygitisbetterthanx.com5
  6. 6. Distributed?? No Centralrepository All developershave a workingcopy and ownprivate repo (.git) Code transfershould be done onnon-private repo. 6Image Source:
  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 : 7
  8. 8. MsysGit for git on Windows 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 MsysGit 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: 10
  11. 11. Introduce yourself to GIT execute commands in bash◦ git config --global <name>◦ git config --global <email>◦ (this gets written to your ~/.gitconfig file) Example◦ git config --global “GeshanManadhar”◦ git config --global“” 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. 12Working Dir with gitPublic git repo on file system
  13. 13. Preparing your working dir 13Nothing significant just created a directory with a file that’s it.
  14. 14. Preparing working dir 2 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.* etc 15
  16. 16. First commit 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 repository 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 publicrepo 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://
  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. 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 master 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. 21
  22. 22. Using .gitignore 22Scenario:Local databasesettings arestored indatabase.phpfile
  23. 23. Continue to push bkp file 23
  24. 24. Pull by a new developer 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. 25
  26. 26. Dev 1 pulled the changes. Dev 1 can immediately have thechanged code. 26
  27. 27. Gitk to know what changed execute gitk on a git repo root to getthis. 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. 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: For details of hashing etc check the gitinternals book. 29
  30. 30. Happy Git-ing Google git See videos on youtube Find some good podcasts on git You will like what you use 30