GIT Intro and usage on
Windows - Basic
By Geshan Manandhar
http://geshan.blogspot.com
1http://geshan.blogspot.com
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
http://geshan.blogspot.com 2
GIT is
 a free & open source, distributed
version control system.
 designed to handle everything from small
to very large projects with speed and
efficiency.
 a developer’s friend in a multi
developer environment.
 a must tool to go back in history to what
you coded and see the code changes
made in the timeline.
3http://geshan.blogspot.com
Who uses GIT
 Many big names including
◦ Linux/Kernel
◦ Eclipse
◦ Ruby on Rails
◦ Android
◦ PostgreSQL
◦ Git itself.
4http://geshan.blogspot.com
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.com
5http://geshan.blogspot.com
Distributed??
 No Central
repository
 All developers
have a working
copy and own
private repo (.git)
 Code transfer
should be done on
non-private repo.
http://geshan.blogspot.com 6
Image Source:
http://coding.smashingmagazine.c
om/2011/07/26/modern-version-
control-with-git-series/
How to use on windows?
 Could not find mature GUI tools like
tortoise SVN.
 Integrated in Eclipse (with plugin) and
NetBeans (good colorful support).
 If you are programmer, you are not
scared of the command line so:
 Download MsysGit :
http://code.google.com/p/msysgit/dow
nloads/list
http://geshan.blogspot.com 7
MsysGit for git on Windows
http://geshan.blogspot.com 8
Steps:
1. Download the exe file (or the portable one, it will not need
installation).
2. Install msysgit , next … next is your friend here with finish – no
need of any fancy configuration.
3. Run the git bash application.
Git bash part of MsysGit
http://geshan.blogspot.com 9
User and line settings for win
 If you are familiar with ~ of unix systems
this might be easy.
 Make sure where your home dir is in
your windows setup like:
◦ /c/users/Geshan – for me in Windows 7
 Set ~/.bash_profile if you want.(google
bash 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-git
http://geshan.blogspot.com 10
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 “Geshan
Manadhar”
◦ git config --global user.email
“me@somedomain.com”
http://geshan.blogspot.com 11
Some conceptual clarity
 You have a working directory and your
private repo (a .git folder in your dir)
 You always push your changes and
pull changes from another non-private
repository.
http://geshan.blogspot.com 12
Working Dir with git
Public git repo on file system
Preparing your working dir
http://geshan.blogspot.com 13
Nothing significant just created a directory with a file that’s it.
Preparing working dir 2
http://geshan.blogspot.com 14
Working directory made
 Commands used
◦ git init ; to initialize the current dir for git
tracking.
◦ 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
http://geshan.blogspot.com 15
First commit
http://geshan.blogspot.com 16
git commit –m “message”;
Files have been put into the local repository (the .git dir
created 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 local
repository.
Always remember to write concise but meaningful
commit messages.
Creating public repository
http://geshan.blogspot.com 17
A bare passive public repo has been created for pushing code.
Remember the path is /c/users/geshan/gitrepos/testgit.git
Different command : git init --bare;
Now we will link the working directory with this public repo.
Linking working dir with public
repo
http://geshan.blogspot.com 18
Remote repository created in previous slide linked to the working directory.
git remote add <name> <path>
Path can be:
File : /home/geshan/gitrepost/testrepo.git
Remote file: ssh://user1@domain1.com/home/user1/gitrepos/test.git
Gitosis: git@domain1.com:test.git
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 and
default branch is master.
http://geshan.blogspot.com 19
First pull attempt
 Pull is done to get the changes done
by others in the self working directory.
 git pull <repo_name> <branch_name>
 git pull origin master
http://geshan.blogspot.com 20
.gitignore file
 .gitignore file is generally placed in the
root of the working directory.
 As the name suggests it can ignore
certain files from git.
 Generally local config is ignored but a
back up is kept for others, example
database username password config.
http://geshan.blogspot.com 21
Using .gitignore
http://geshan.blogspot.com 22
Scenario:
Local database
settings are
stored in
database.php
file
Continue to push bkp file
http://geshan.blogspot.com 23
Pull by a new developer
http://geshan.blogspot.com 24
A new
developer
will
generally
clone the
project,
than
create
new files.
-Notice
git remote
–v
Git branch
shows
available
branches.
Scenario dev 2 posts code
 Dev 2 changed test.txt and pushed his
code to public repo.
http://geshan.blogspot.com 25
Dev 1 pulled the changes.
 Dev 1 can immediately have the
changed code.
http://geshan.blogspot.com 26
Gitk to know what changed
 execute gitk on a git repo root to get
this.
http://geshan.blogspot.com 27
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
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 git
internals book.
http://geshan.blogspot.com 29
Happy Git-ing
 Google git
 See videos on youtube
 Find some good podcasts on git
 You will like what you use
http://geshan.blogspot.com 30

Git intro hands on windows with msysgit

  • 1.
    GIT Intro andusage on Windows - Basic By Geshan Manandhar http://geshan.blogspot.com 1http://geshan.blogspot.com
  • 2.
    Agenda  What isgit  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 http://geshan.blogspot.com 2
  • 3.
    GIT is  afree & open source, distributed version control system.  designed to handle everything from small to very large projects with speed and efficiency.  a developer’s friend in a multi developer environment.  a must tool to go back in history to what you coded and see the code changes made in the timeline. 3http://geshan.blogspot.com
  • 4.
    Who uses GIT Many big names including ◦ Linux/Kernel ◦ Eclipse ◦ Ruby on Rails ◦ Android ◦ PostgreSQL ◦ Git itself. 4http://geshan.blogspot.com
  • 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.com 5http://geshan.blogspot.com
  • 6.
    Distributed??  No Central repository All developers have a working copy and own private repo (.git)  Code transfer should be done on non-private repo. http://geshan.blogspot.com 6 Image Source: http://coding.smashingmagazine.c om/2011/07/26/modern-version- control-with-git-series/
  • 7.
    How to useon windows?  Could not find mature GUI tools like tortoise SVN.  Integrated in Eclipse (with plugin) and NetBeans (good colorful support).  If you are programmer, you are not scared of the command line so:  Download MsysGit : http://code.google.com/p/msysgit/dow nloads/list http://geshan.blogspot.com 7
  • 8.
    MsysGit for giton Windows http://geshan.blogspot.com 8 Steps: 1. Download the exe file (or the portable one, it will not need installation). 2. Install msysgit , next … next is your friend here with finish – no need of any fancy configuration. 3. Run the git bash application.
  • 9.
    Git bash partof MsysGit http://geshan.blogspot.com 9
  • 10.
    User and linesettings for win  If you are familiar with ~ of unix systems this might be easy.  Make sure where your home dir is in your windows setup like: ◦ /c/users/Geshan – for me in Windows 7  Set ~/.bash_profile if you want.(google bash 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-git http://geshan.blogspot.com 10
  • 11.
    Introduce yourself toGIT  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 “Geshan Manadhar” ◦ git config --global user.email “me@somedomain.com” http://geshan.blogspot.com 11
  • 12.
    Some conceptual clarity You have a working directory and your private repo (a .git folder in your dir)  You always push your changes and pull changes from another non-private repository. http://geshan.blogspot.com 12 Working Dir with git Public git repo on file system
  • 13.
    Preparing your workingdir http://geshan.blogspot.com 13 Nothing significant just created a directory with a file that’s it.
  • 14.
    Preparing working dir2 http://geshan.blogspot.com 14
  • 15.
    Working directory made Commands used ◦ git init ; to initialize the current dir for git tracking. ◦ 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 http://geshan.blogspot.com 15
  • 16.
    First commit http://geshan.blogspot.com 16 gitcommit –m “message”; Files have been put into the local repository (the .git dir created 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 local repository. Always remember to write concise but meaningful commit messages.
  • 17.
    Creating public repository http://geshan.blogspot.com17 A bare passive public repo has been created for pushing code. Remember the path is /c/users/geshan/gitrepos/testgit.git Different command : git init --bare; Now we will link the working directory with this public repo.
  • 18.
    Linking working dirwith public repo http://geshan.blogspot.com 18 Remote repository created in previous slide linked to the working directory. git remote add <name> <path> Path can be: File : /home/geshan/gitrepost/testrepo.git Remote file: ssh://user1@domain1.com/home/user1/gitrepos/test.git Gitosis: git@domain1.com:test.git
  • 19.
    First push toremote 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 and default branch is master. http://geshan.blogspot.com 19
  • 20.
    First pull attempt Pull is done to get the changes done by others in the self working directory.  git pull <repo_name> <branch_name>  git pull origin master http://geshan.blogspot.com 20
  • 21.
    .gitignore file  .gitignorefile is generally placed in the root of the working directory.  As the name suggests it can ignore certain files from git.  Generally local config is ignored but a back up is kept for others, example database username password config. http://geshan.blogspot.com 21
  • 22.
    Using .gitignore http://geshan.blogspot.com 22 Scenario: Localdatabase settings are stored in database.php file
  • 23.
    Continue to pushbkp file http://geshan.blogspot.com 23
  • 24.
    Pull by anew developer http://geshan.blogspot.com 24 A new developer will generally clone the project, than create new files. -Notice git remote –v Git branch shows available branches.
  • 25.
    Scenario dev 2posts code  Dev 2 changed test.txt and pushed his code to public repo. http://geshan.blogspot.com 25
  • 26.
    Dev 1 pulledthe changes.  Dev 1 can immediately have the changed code. http://geshan.blogspot.com 26
  • 27.
    Gitk to knowwhat changed  execute gitk on a git repo root to get this. http://geshan.blogspot.com 27
  • 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.
    Things to lookat  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 git internals book. http://geshan.blogspot.com 29
  • 30.
    Happy Git-ing  Googlegit  See videos on youtube  Find some good podcasts on git  You will like what you use http://geshan.blogspot.com 30