SlideShare a Scribd company logo
1 of 33
Download to read offline
GIT BASICS

Presenter: Don Lee
What is GIT
       (local) GIT ===> SVN/GIT (repo)

● GIT is a distributed version control system (DVCS).
● Our repo can be SVN or GIT
● It only interface with SVN when
    ○ read ==> sync to repo
    ○ write ==> submit to repo
● With GIT, all changes are store locally.
● SVN repo (svn://svn.tagged.com)
● GIT repo (https://git.tagged.com/git)
GIT Vs SVN
● Git clone (url) gives you a complete copy of
  the entire history of that project.
● Every operation is now done off data on
  your local disk, meaning that it is both
  unbeliveably fast and can be done offline.
● No single point of failure (such as SVN
  server crash), everyone has full backup of
  the project data.
● It doesn't depend on 1 centralized server,
  you can add multiple remote repositories to
  your project.
Three States
● HEAD - last commit snapshot, local repo
● Index - proposed next commit snapshot
● working directory (WD) - sandbox
Installation
 ● Linux - sudo apt-get install git-core
   -sudo apt-get install git-svn

 ● Mac OS - Download and install from HERE.

 ● Windows 7 - Install cywin and enable git*, svn*, perl*, python,
   wget packages where * means wild card
Configuration

1. Open a terminal and create a .gitconfig file in your home directory
and then add/edit ~/.gitconfig file as follows:
[user]
  name = Don Lee
  email = dlee@tagged.com
[reviewboard]
    url = https://scm.tagged.com/reviewboard
[alias]
  ci = commit
  up = update
  st = status
  br = branch
  co = checkout
  di = diff
  lg = log --graph --decorate
  gl = log -p
  glp = log --graph --oneline --abbrev-commit --decorate
  rl = reflog
  llog = log --date=local
  ol = log --oneline
  w = whatchanged
  sta = stash
  rb = !post-review --parent=trunk --guess-description --username=dlee -o
  rb-diff = !post-review -n --parent=trunk
  sdiff = !git-svn-diff
[log]
   date = local
[color]
    ui = auto
[color "diff"]
    whitespace = red reverse
[core]
    whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
Review Board Setup
 1. Download any one of the TAR file in http://downloads.
    reviewboard.org/releases/RBTools/0.3
 2. Extract the files into home directory
 3. mv <folder name> RBtools
 4. cd ~/RBtools
 5. python setup.py install
 6. mv <downloaded EGG file> RBtools.egg
 7. easy_install RBtools.egg
 8. Download git-svn-diff from: https://gist.github.com/44537 and
    add it somewhere in your PATH.
Note:
Linux users can install python by
apt-get install python-setuptools

For Windows 7 user, in order to get "apt-get", use apt-cyg instead
svn --force export http://apt-cyg.googlecode.com/svn/trunk/ /bin/
chmod +x /bin/apt-cyg
Getting SVN/GIT repo
git svn clone <repo url> <target directory>

Example:

git svn clone svn://svn.tagged.com/web/trunk .

It is getting the repo from web project to current
directory.
Note: For GIT Repo, use
git clone ssh://username@git.tagged.
com/git/engteam/<project name>.git
Getting the repo (con't)

A faster way to get repo is to copy all the directory/files
from a colleague who is already migrated to GIT, and
then issue the command above to sync to with the repo
Sync to SVN/GIT repo
git svn rebase

This will sync your branch to the latest version in the
SVN repo.

Note: For user with GIT repo, use the following
instead

git pull
Branching
git br <new branch name>

This command creates a new branch and it would have
the same version as the master branch. If you don't input
a name, it will just show you existing branch.Ex:
         git br newBranch
Switching branch
git co <branch name>
This command switch to a another branch. Please try to do changes on the
branch and leave the master clean because most likely you are doing diff with
the master branch later.
Example:
   git co newBranch
   git br
output:
   master
 * newBranch      (notice the * has change to point to newBranch)

There is a combo command which let you create a new branch AND switches
to the new branch

git co -b newBranch
Add a file
git add <filesnames>

This command add files to index.

Example:
  git add shared/class/tag/{dao/a.php,b.php}

This command will add to files a.php in dao subdirectory
and b.php
Remove file
git rm <filesnames>        remove files in index
git rm <filename> --cached remove from staging,
file still exists



Example:
  git rm shared/class/tag/{dao/a.php,b.php}

This command will remove files a.php in dao
subdirectory and b.php
Moving file
git mv <filesnames> <destination file location>

This command moves files in index.

Example:
  git mv shared/class/tag/a.php .

This command will move file a.php to current directory.
Checking status
git st

This command displays the changes so far in the working
directory i.e. what file are modified.


Reverting mistake
git reset --soft commit_id move HEAD to commit id
git reset commit_id move HEAD & index to commit id
git reset --hard commit_id move ALL to commit id

commit_id if not supply means HEAD. For example git reset will
unstage files in index to working dir
Reverting mistake
git co commit_id <filename>
Change a working directory file to the a version specify by commit
id. If not specified, Ex: git co, it means get HEAD version of all files
in current dir.

git co -- <filename or path>
Clear working directory for specific file or specific path (recursively)

git reset HEAD <filename>
Unstage a file

git revert HEAD
Creates "another" new commit that revert earlier change.
Ignoring file
cd ~
vim .gitignore

list out the full path of the filename to ignore

git config --global core.excludesfile ~/.gitignore

It ignore any files you may want the GIT to ignore.
Stashing
git sta save "a name identifier"

If you are not ready to commit stuff, but you need to save
the stuff that are modify, use the command above.

git sta list
to look at all the save list

git sta apply <optional nth list>
This would just dump out the specific stash.Example:
git stash apply stash@{0}
Commit change
git ci -a commit all index and WD to branch
git ci     commit only index to branch
git ci -m "blah" commit with commit message "blah"
git ci --amend modify the existing commit


Diffing
git di                 diff WD and index
git di --cached         diff index and HEAD
git di master newbranch diff between branches
Inspect commits
git lg List all the commit ids and description in that branch in decending order with
the latest commit at the top. The argument can be compound.
git gl Show the code diff as well
git lg -2 Show only last 2
git glp Show 1 line for each commit
git lg --since=2.weeks last 2 weeks
git lg --since="2011-09-01" since September 1st 2011
git lg --until="2011-09-01" until September 1st 2011
git lg --author="dlee" author is dlee
git lg --committer="dlee" committer is dlee


git show <commit id>
output:
{all the code diff for the particular commit}
Inspect Git Log
git rl   List all the actions you did in git




Remote Repo URL
git remote -v    List all the remote repo URL




Find the culprit
git blame <filename>      List all the people who change the file.
Merging change
git merge <branch name to merge into >

Merges the branch name to the current branch.


Conflict
Git will try to auto-resolve a conflict if it can, however, when it fails to do so,
you can use a conflict resolve tool, there are several out there, one good one
is meld.

git mergetool

trigger a interactive UI where you can click on which one you want to
merge.
Interactive mode
git rebase -i HEAD~<no. commit involved>

This will trigger interactive mode which will allow you
to play with the commit message, squash serveral
commits into 1.
# Rebase a257c40..90a4507 onto a257c40
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
Interactive mode (con't)
Squashing serveral commit into 1


git rebase -i HEAD~ <no. of commits>

Example:
pick 90a4507 pick me

pick 90a4508 squash me
pick 90a4509 squash me

change to

pick 90a4507 pick me
s 90a4508 squash me
s 90a4509 squash me

and then save.
In the next pop-up just put a "#" on the comments you don't want.
Interactive mode (con't)
Reverting a file from latest commit while in a branch


git co master <filename>
git commit -a
git rebase -i HEAD~2 squash the two commit
into one.
Note there is an easier way:
git co master <filename>
git commit --amend

Checkout the master copy of filename, commit it into the branch and
then squash the commits.
Creating patch
git format-patch <commit id> ~ <no. of commit>


If you changes is the latest commit, commit id shall be
HEAD.

git rb-diff > patch.diff

This creates a SVN patch diff.
Apply patch

git apply <the diff file>



apply the changes by others.
Please note this doesn't work with existing svn diff
patch file.
Review Board
post-review

Submitting code review to review board is easy with just type the
command above. However, you still need to enter the group, review
name and etc. The diff portion is handled for you already. (Note for
GIT-repo, you might need to remove --parent=trunk in .gitconfig)

post-review -r <revision number in RB>

If you want to update diff in review board, just is type the command
above with the revision number in RB.
Push to SVN or GIT
git svn dcommit

this shall submit the changes to the SVN repo.

Note: For GIT Repo user, use the following command instead
git push

Deleting branch
git br -D <newBranch>
You work is done, remove the temp branch.
Need help ?
git help <command>

If you don't specify the command name, it will just list out all
the commands that are available.
FAQ
1) After unpacking the source code and syncing the latest, git st gives a list of changes which I did not modify.
resolution: git reset --hard

2)Win 7 user, I get a call stack crash stating remap error when I issue a git svn rebase.
resolution: Close out of Cygwin (and all cygwin processes) , go to your cygwin bin directory, and type ash '/usr/bin/rebaseall'

3) Why do I get the error ? update-index --refresh: command returned error: 1
resolution: You need to either save your current changes using stash (i.e. git sta save <name>) or commit your changes (i.e. git ci -a) before
you can sync with repo.

4) How do I commit my changes to repo if I have several commits ?
resolution: Git only commit your latest changes, You can squash several commit into one latest commit before submitting to repo.

5) How do I see the commits in my local branch ?
resolution: git lg
Free Assistance

For those who are interested to transition to GIT
next week (limited time offer), we will sit with you
and help you to set up.

Don, dlee@tagged.com
Nate, nkresge@tagged.com

More Related Content

What's hot

Introduction to Git / Github
Introduction to Git / GithubIntroduction to Git / Github
Introduction to Git / GithubPaige Bailey
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginnersbryanbibat
 
My Notes from https://www.codeschool.com/courses/git-real
My Notes from  https://www.codeschool.com/courses/git-realMy Notes from  https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-realEneldo Serrata
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notesSurabhi Gupta
 
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git John Tighe
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-itAutomat-IT
 
Introduction To Git For Version Control Architecture And Common Commands Comp...
Introduction To Git For Version Control Architecture And Common Commands Comp...Introduction To Git For Version Control Architecture And Common Commands Comp...
Introduction To Git For Version Control Architecture And Common Commands Comp...SlideTeam
 
Sample Build Automation Commands
Sample Build Automation CommandsSample Build Automation Commands
Sample Build Automation CommandsJoseph Dante
 
Github - Le Wagon Melbourne
Github - Le Wagon MelbourneGithub - Le Wagon Melbourne
Github - Le Wagon MelbournePaal Ringstad
 
Git and GitHub at the San Francisco JUG
 Git and GitHub at the San Francisco JUG Git and GitHub at the San Francisco JUG
Git and GitHub at the San Francisco JUGMatthew McCullough
 

What's hot (20)

Introduction to Git / Github
Introduction to Git / GithubIntroduction to Git / Github
Introduction to Git / Github
 
Version Control with Git for Beginners
Version Control with Git for BeginnersVersion Control with Git for Beginners
Version Control with Git for Beginners
 
Use Git like a pro - condensed
Use Git like a pro - condensedUse Git like a pro - condensed
Use Git like a pro - condensed
 
My Notes from https://www.codeschool.com/courses/git-real
My Notes from  https://www.codeschool.com/courses/git-realMy Notes from  https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-real
 
Git basics with notes
Git basics with notesGit basics with notes
Git basics with notes
 
Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git Git 101 - An introduction to Version Control using Git
Git 101 - An introduction to Version Control using Git
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Github
GithubGithub
Github
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git workflows automat-it
Git workflows automat-itGit workflows automat-it
Git workflows automat-it
 
Go 1.8 Release Party
Go 1.8 Release PartyGo 1.8 Release Party
Go 1.8 Release Party
 
Introduction To Git For Version Control Architecture And Common Commands Comp...
Introduction To Git For Version Control Architecture And Common Commands Comp...Introduction To Git For Version Control Architecture And Common Commands Comp...
Introduction To Git For Version Control Architecture And Common Commands Comp...
 
Git
GitGit
Git
 
Sample Build Automation Commands
Sample Build Automation CommandsSample Build Automation Commands
Sample Build Automation Commands
 
Did you git yet?
Did you git yet?Did you git yet?
Did you git yet?
 
Git & GitHub WorkShop
Git & GitHub WorkShopGit & GitHub WorkShop
Git & GitHub WorkShop
 
Github - Le Wagon Melbourne
Github - Le Wagon MelbourneGithub - Le Wagon Melbourne
Github - Le Wagon Melbourne
 
Git and GitHub at the San Francisco JUG
 Git and GitHub at the San Francisco JUG Git and GitHub at the San Francisco JUG
Git and GitHub at the San Francisco JUG
 
Git Real
Git RealGit Real
Git Real
 

Viewers also liked

Node.js by Alex and Nalin
Node.js by Alex and NalinNode.js by Alex and Nalin
Node.js by Alex and NalinTagged Social
 
Architecture Summer Camp1
Architecture  Summer Camp1Architecture  Summer Camp1
Architecture Summer Camp1Bhanu Kharbanda
 
Definitions
DefinitionsDefinitions
Definitionspliis12
 
Design for Engineers
Design for EngineersDesign for Engineers
Design for EngineersTagged Social
 
June24 presentation2
June24 presentation2June24 presentation2
June24 presentation2Molly Sharp
 
Definitions
DefinitionsDefinitions
Definitionspliis12
 
Git &amp; git hub v1.2
Git &amp; git hub v1.2Git &amp; git hub v1.2
Git &amp; git hub v1.2Chris Chen
 
Git extension-training
Git extension-trainingGit extension-training
Git extension-trainingEric Guo
 
Advanced Git
Advanced GitAdvanced Git
Advanced Gitsegv
 

Viewers also liked (12)

Node.js by Alex and Nalin
Node.js by Alex and NalinNode.js by Alex and Nalin
Node.js by Alex and Nalin
 
Architecture Summer Camp1
Architecture  Summer Camp1Architecture  Summer Camp1
Architecture Summer Camp1
 
Definitions
DefinitionsDefinitions
Definitions
 
Design for Engineers
Design for EngineersDesign for Engineers
Design for Engineers
 
June24 presentation2
June24 presentation2June24 presentation2
June24 presentation2
 
Definitions
DefinitionsDefinitions
Definitions
 
Git &amp; git hub v1.2
Git &amp; git hub v1.2Git &amp; git hub v1.2
Git &amp; git hub v1.2
 
Git SVN Migrate Reasons
Git SVN Migrate ReasonsGit SVN Migrate Reasons
Git SVN Migrate Reasons
 
Git and git hub
Git and git hubGit and git hub
Git and git hub
 
Git extension-training
Git extension-trainingGit extension-training
Git extension-training
 
From SVN to Git
From SVN to GitFrom SVN to Git
From SVN to Git
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 

Similar to GIT Basics (20)

Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
Git commands
Git commandsGit commands
Git commands
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
SVN 2 Git
SVN 2 GitSVN 2 Git
SVN 2 Git
 
Git cheat-sheet 2021
Git cheat-sheet 2021Git cheat-sheet 2021
Git cheat-sheet 2021
 
Git cheat-sheet
Git cheat-sheetGit cheat-sheet
Git cheat-sheet
 
Git
GitGit
Git
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
Git basic
Git basicGit basic
Git basic
 
DrupalCafe5 VCS
DrupalCafe5 VCSDrupalCafe5 VCS
DrupalCafe5 VCS
 
Git github
Git githubGit github
Git github
 
Honestly Git Playground 20190221
Honestly Git Playground 20190221Honestly Git Playground 20190221
Honestly Git Playground 20190221
 
Lets Git Together
Lets Git TogetherLets Git Together
Lets Git Together
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
 
Git
GitGit
Git
 

Recently uploaded

(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)oannq
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxJackieSparrow3
 
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...JeylaisaManabat1
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxShubham Rawat
 

Recently uploaded (6)

(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptx
 
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptx
 

GIT Basics

  • 2. What is GIT (local) GIT ===> SVN/GIT (repo) ● GIT is a distributed version control system (DVCS). ● Our repo can be SVN or GIT ● It only interface with SVN when ○ read ==> sync to repo ○ write ==> submit to repo ● With GIT, all changes are store locally. ● SVN repo (svn://svn.tagged.com) ● GIT repo (https://git.tagged.com/git)
  • 3. GIT Vs SVN ● Git clone (url) gives you a complete copy of the entire history of that project. ● Every operation is now done off data on your local disk, meaning that it is both unbeliveably fast and can be done offline. ● No single point of failure (such as SVN server crash), everyone has full backup of the project data. ● It doesn't depend on 1 centralized server, you can add multiple remote repositories to your project.
  • 4. Three States ● HEAD - last commit snapshot, local repo ● Index - proposed next commit snapshot ● working directory (WD) - sandbox
  • 5. Installation ● Linux - sudo apt-get install git-core -sudo apt-get install git-svn ● Mac OS - Download and install from HERE. ● Windows 7 - Install cywin and enable git*, svn*, perl*, python, wget packages where * means wild card Configuration 1. Open a terminal and create a .gitconfig file in your home directory and then add/edit ~/.gitconfig file as follows:
  • 6. [user] name = Don Lee email = dlee@tagged.com [reviewboard] url = https://scm.tagged.com/reviewboard [alias] ci = commit up = update st = status br = branch co = checkout di = diff lg = log --graph --decorate gl = log -p glp = log --graph --oneline --abbrev-commit --decorate rl = reflog llog = log --date=local ol = log --oneline w = whatchanged sta = stash rb = !post-review --parent=trunk --guess-description --username=dlee -o rb-diff = !post-review -n --parent=trunk sdiff = !git-svn-diff [log] date = local [color] ui = auto [color "diff"] whitespace = red reverse [core] whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
  • 7. Review Board Setup 1. Download any one of the TAR file in http://downloads. reviewboard.org/releases/RBTools/0.3 2. Extract the files into home directory 3. mv <folder name> RBtools 4. cd ~/RBtools 5. python setup.py install 6. mv <downloaded EGG file> RBtools.egg 7. easy_install RBtools.egg 8. Download git-svn-diff from: https://gist.github.com/44537 and add it somewhere in your PATH. Note: Linux users can install python by apt-get install python-setuptools For Windows 7 user, in order to get "apt-get", use apt-cyg instead svn --force export http://apt-cyg.googlecode.com/svn/trunk/ /bin/ chmod +x /bin/apt-cyg
  • 8. Getting SVN/GIT repo git svn clone <repo url> <target directory> Example: git svn clone svn://svn.tagged.com/web/trunk . It is getting the repo from web project to current directory. Note: For GIT Repo, use git clone ssh://username@git.tagged. com/git/engteam/<project name>.git
  • 9. Getting the repo (con't) A faster way to get repo is to copy all the directory/files from a colleague who is already migrated to GIT, and then issue the command above to sync to with the repo
  • 10. Sync to SVN/GIT repo git svn rebase This will sync your branch to the latest version in the SVN repo. Note: For user with GIT repo, use the following instead git pull
  • 11. Branching git br <new branch name> This command creates a new branch and it would have the same version as the master branch. If you don't input a name, it will just show you existing branch.Ex: git br newBranch
  • 12. Switching branch git co <branch name> This command switch to a another branch. Please try to do changes on the branch and leave the master clean because most likely you are doing diff with the master branch later. Example: git co newBranch git br output: master * newBranch (notice the * has change to point to newBranch) There is a combo command which let you create a new branch AND switches to the new branch git co -b newBranch
  • 13. Add a file git add <filesnames> This command add files to index. Example: git add shared/class/tag/{dao/a.php,b.php} This command will add to files a.php in dao subdirectory and b.php
  • 14. Remove file git rm <filesnames> remove files in index git rm <filename> --cached remove from staging, file still exists Example: git rm shared/class/tag/{dao/a.php,b.php} This command will remove files a.php in dao subdirectory and b.php
  • 15. Moving file git mv <filesnames> <destination file location> This command moves files in index. Example: git mv shared/class/tag/a.php . This command will move file a.php to current directory.
  • 16. Checking status git st This command displays the changes so far in the working directory i.e. what file are modified. Reverting mistake git reset --soft commit_id move HEAD to commit id git reset commit_id move HEAD & index to commit id git reset --hard commit_id move ALL to commit id commit_id if not supply means HEAD. For example git reset will unstage files in index to working dir
  • 17. Reverting mistake git co commit_id <filename> Change a working directory file to the a version specify by commit id. If not specified, Ex: git co, it means get HEAD version of all files in current dir. git co -- <filename or path> Clear working directory for specific file or specific path (recursively) git reset HEAD <filename> Unstage a file git revert HEAD Creates "another" new commit that revert earlier change.
  • 18. Ignoring file cd ~ vim .gitignore list out the full path of the filename to ignore git config --global core.excludesfile ~/.gitignore It ignore any files you may want the GIT to ignore.
  • 19. Stashing git sta save "a name identifier" If you are not ready to commit stuff, but you need to save the stuff that are modify, use the command above. git sta list to look at all the save list git sta apply <optional nth list> This would just dump out the specific stash.Example: git stash apply stash@{0}
  • 20. Commit change git ci -a commit all index and WD to branch git ci commit only index to branch git ci -m "blah" commit with commit message "blah" git ci --amend modify the existing commit Diffing git di diff WD and index git di --cached diff index and HEAD git di master newbranch diff between branches
  • 21. Inspect commits git lg List all the commit ids and description in that branch in decending order with the latest commit at the top. The argument can be compound. git gl Show the code diff as well git lg -2 Show only last 2 git glp Show 1 line for each commit git lg --since=2.weeks last 2 weeks git lg --since="2011-09-01" since September 1st 2011 git lg --until="2011-09-01" until September 1st 2011 git lg --author="dlee" author is dlee git lg --committer="dlee" committer is dlee git show <commit id> output: {all the code diff for the particular commit}
  • 22. Inspect Git Log git rl List all the actions you did in git Remote Repo URL git remote -v List all the remote repo URL Find the culprit git blame <filename> List all the people who change the file.
  • 23. Merging change git merge <branch name to merge into > Merges the branch name to the current branch. Conflict Git will try to auto-resolve a conflict if it can, however, when it fails to do so, you can use a conflict resolve tool, there are several out there, one good one is meld. git mergetool trigger a interactive UI where you can click on which one you want to merge.
  • 24. Interactive mode git rebase -i HEAD~<no. commit involved> This will trigger interactive mode which will allow you to play with the commit message, squash serveral commits into 1. # Rebase a257c40..90a4507 onto a257c40 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted.
  • 25. Interactive mode (con't) Squashing serveral commit into 1 git rebase -i HEAD~ <no. of commits> Example: pick 90a4507 pick me pick 90a4508 squash me pick 90a4509 squash me change to pick 90a4507 pick me s 90a4508 squash me s 90a4509 squash me and then save. In the next pop-up just put a "#" on the comments you don't want.
  • 26. Interactive mode (con't) Reverting a file from latest commit while in a branch git co master <filename> git commit -a git rebase -i HEAD~2 squash the two commit into one. Note there is an easier way: git co master <filename> git commit --amend Checkout the master copy of filename, commit it into the branch and then squash the commits.
  • 27. Creating patch git format-patch <commit id> ~ <no. of commit> If you changes is the latest commit, commit id shall be HEAD. git rb-diff > patch.diff This creates a SVN patch diff.
  • 28. Apply patch git apply <the diff file> apply the changes by others. Please note this doesn't work with existing svn diff patch file.
  • 29. Review Board post-review Submitting code review to review board is easy with just type the command above. However, you still need to enter the group, review name and etc. The diff portion is handled for you already. (Note for GIT-repo, you might need to remove --parent=trunk in .gitconfig) post-review -r <revision number in RB> If you want to update diff in review board, just is type the command above with the revision number in RB.
  • 30. Push to SVN or GIT git svn dcommit this shall submit the changes to the SVN repo. Note: For GIT Repo user, use the following command instead git push Deleting branch git br -D <newBranch> You work is done, remove the temp branch.
  • 31. Need help ? git help <command> If you don't specify the command name, it will just list out all the commands that are available.
  • 32. FAQ 1) After unpacking the source code and syncing the latest, git st gives a list of changes which I did not modify. resolution: git reset --hard 2)Win 7 user, I get a call stack crash stating remap error when I issue a git svn rebase. resolution: Close out of Cygwin (and all cygwin processes) , go to your cygwin bin directory, and type ash '/usr/bin/rebaseall' 3) Why do I get the error ? update-index --refresh: command returned error: 1 resolution: You need to either save your current changes using stash (i.e. git sta save <name>) or commit your changes (i.e. git ci -a) before you can sync with repo. 4) How do I commit my changes to repo if I have several commits ? resolution: Git only commit your latest changes, You can squash several commit into one latest commit before submitting to repo. 5) How do I see the commits in my local branch ? resolution: git lg
  • 33. Free Assistance For those who are interested to transition to GIT next week (limited time offer), we will sit with you and help you to set up. Don, dlee@tagged.com Nate, nkresge@tagged.com