The document provides an overview of Travis Swicegood's pragmatic guide to using Git. It covers topics such as installing Git, configuring user settings, creating and cloning repositories, tracking changes through commits, branching and merging, and collaborating through pushing and pulling changes. The guide is presented through explanatory text and example Git commands.
16. Installation–Compiling
… download latest source from git-scm.com…
prompt> make && make install
… if you’re adventurous…
prompt> make docs && make install-docs
pragmatic guide to git by travis swicegood some rights reserved
17. Installation–Ubuntu
prompt> apt-get install git-core
… optional …
prompt> apt-get install git-doc git-svn
pragmatic guide to git by travis swicegood some rights reserved
18. Installation–Windows
Cygwin: http://cygwin.org
msysGit:
http://code.google.com/p/msysgit/
pragmatic guide to git by travis swicegood some rights reserved
19. Installation–OS X
prompt> brew install git
–OR–
Git OS X Installer:
http://code.google.com/p/git-osx-installer/
pragmatic guide to git by travis swicegood some rights reserved
20. Verifying the Install
prompt> git --version
git version 1.7.3.2
pragmatic guide to git by travis swicegood some rights reserved
21. My Version
prompt> git --version
git version 1.7.3.2
hub version 1.4.1
pragmatic guide to git by travis swicegood some rights reserved
22. Getting
Help
pragmatic guide to git by travis swicegood some rights reserved
23. Built-in Help
prompt> git help
prompt> git help <some command>
prompt> open http://j.mp/gitdocs/
pragmatic guide to git by travis swicegood some rights reserved
30. Initialization
prompt> git init
… example …
prompt> mkdir /work/some-repo
prompt> cd /work/some-repo
prompt> git init
pragmatic guide to git by travis swicegood some rights reserved
31. Working
Tree
pragmatic guide to git by travis swicegood some rights reserved
33. Cloning
prompt> git clone <some repo>
… example …
prompt> git clone
git://github.com/tswicegood/bobby-tables.git
prompt> cd bobby-tables
pragmatic guide to git by travis swicegood some rights reserved
34. Cloning
prompt> git clone <some repo>
… example …
prompt> git clone
git://github.com/tswicegood/bobby-tables.git
prompt> cd bobby-tables
pragmatic guide to git by travis swicegood some rights reserved
36. Seeing What’s
Changed
pragmatic guide to git by travis swicegood some rights reserved
37. Status
prompt> git status
… example …
prompt> git status
# On branch master
nothing to commit (working directory clean)
pragmatic guide to git by travis swicegood some rights reserved
38. Staging
Changes
pragmatic guide to git by travis swicegood some rights reserved
40. (aka)
Staging
Area
pragmatic guide to git by travis swicegood some rights reserved
41. Adding a New File
prompt> git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what…
#
# README.rst
pragmatic guide to git by travis swicegood some rights reserved
42. Adding a New File
prompt> git add README.rst
prompt> git status
# On branch master
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: README.rst
pragmatic guide to git by travis swicegood some rights reserved
43. Committing
Changes
pragmatic guide to git by travis swicegood some rights reserved
44. Creating a Commit
prompt> git commit -m “some great message”
[master 600f084] some great message
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.rst
pragmatic guide to git by travis swicegood some rights reserved
45. Creating a Commit
prompt> git commit -m “some great message”
[master 600f084] some great message
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.rst
pragmatic guide to git by travis swicegood some rights reserved
46. Creating a Commit
prompt> git commit -m “some great message”
[master 600f084] some great message
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.rst
pragmatic guide to git by travis swicegood some rights reserved
47. Creating a Commit
prompt> git commit -m “some great message”
[master 600f084] some great message
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README.rst
… or use the editor …
prompt> git commit
pragmatic guide to git by travis swicegood some rights reserved
48. Git’s Editor?
GIT_EDITOR <-- environment var
core.editor <-- set with git config --global
VISUAL <-- environment var
EDITOR <-- environment var
vi <-- when all else fails
pragmatic guide to git by travis swicegood some rights reserved
49. Staging
Changes (Part II)
pragmatic guide to git by travis swicegood some rights reserved
50. Adding an Existing File
prompt> git add README.rst
prompt> git status
# On branch master
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# modified file: README.rst
pragmatic guide to git by travis swicegood some rights reserved
51. Commit Existing File
prompt> git commit -m “great message”
README.rst
[master 3dc20b0] great message
1 files changed, 1 insertions(+), 0 deletions(-)
pragmatic guide to git by travis swicegood some rights reserved
52. Commit All Changes
prompt> git commit -m “great message” -a
[master be1b8dc] great message
1 files changed, 1 insertions(+), 0 deletions(-)
pragmatic guide to git by travis swicegood some rights reserved
53. Adding Part of a File
prompt> git add -p README.rst
… editor launches …
pragmatic guide to git by travis swicegood some rights reserved
54. Undoing
Staged
Changes
pragmatic guide to git by travis swicegood some rights reserved
55. Remove a Staged Change
prompt> git reset HEAD README.rst
M README.rst
pragmatic guide to git by travis swicegood some rights reserved
56. Moving
Files
pragmatic guide to git by travis swicegood some rights reserved
57. Moving a File
prompt> git mv README.rst README.txt
prompt> git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: README.rst -> README.txt
pragmatic guide to git by travis swicegood some rights reserved
58. Deleting
Files
pragmatic guide to git by travis swicegood some rights reserved
59. Deleting a File
prompt> git rm README.txt
rm 'README.txt'
prompt> git status
# On branch master
…
# deleted: README.txt
pragmatic guide to git by travis swicegood some rights reserved
60. Sharing
Changes
pragmatic guide to git by travis swicegood some rights reserved
61. Sharing
Changes
(from 30,000 feet)
pragmatic guide to git by travis swicegood some rights reserved
62. Sending Your Changes
prompt> git push <remote> [<branch>]
… example …
prompt> git push origin master
pragmatic guide to git by travis swicegood some rights reserved
63. Sending Your Changes
prompt> git push <remote> [<branch>]
… example …
prompt> git push origin master
pragmatic guide to git by travis swicegood some rights reserved
64. Grabbing Other’s Changes
prompt> git pull <remote> [<branch>]
… example …
prompt> git pull tswicegood master
pragmatic guide to git by travis swicegood some rights reserved
65. Told ya…
30,000’
pragmatic guide to git by travis swicegood some rights reserved
71. Creating a New Branch
prompt> git branch <new branch> [<existing>]
… example …
prompt> git branch new-branch
prompt> git branch
* master
new-branch
pragmatic guide to git by travis swicegood some rights reserved
77. Merging Branches
prompt> git checkout master
Switched to branch 'master'
prompt> git merge newest-branch
Updating 94f1967..a053b49
Fast-forward
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 foo
pragmatic guide to git by travis swicegood some rights reserved
78. Merging Branches
prompt> git checkout master
Switched to branch 'master'
prompt> git merge newest-branch
Updating 94f1967..a053b49
Fast-forward
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 foo
pragmatic guide to git by travis swicegood some rights reserved
79. Fast Forward
newest-branch
master
pragmatic guide to git by travis swicegood some rights reserved
80. Fast Forward
newest-branch
master
pragmatic guide to git by travis swicegood some rights reserved
81. Merging Branches
prompt> git merge new-branch
Merge made by recursive.
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 bar
pragmatic guide to git by travis swicegood some rights reserved
82. Merging Branches
prompt> git merge new-branch
Merge made by recursive.
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 bar
pragmatic guide to git by travis swicegood some rights reserved
83. Recursive Merge
new-branch
master
pragmatic guide to git by travis swicegood some rights reserved
84. Recursive Merge
new-branch
master
pragmatic guide to git by travis swicegood some rights reserved
86. Rebasing Branches
prompt> git checkout new-branch
Switched to branch 'new-branch'
prompt> git rebase master
First, rewinding head to replay your work on
top of it...
Applying: …
pragmatic guide to git by travis swicegood some rights reserved
87. Before Rebasing
new-branch
master
pragmatic guide to git by travis swicegood some rights reserved
88. After Rebasing
new-branch
master
pragmatic guide to git by travis swicegood some rights reserved
89. Rebasing Branches
prompt> git checkout new-branch
Switched to branch 'new-branch'
prompt> git rebase master
First, rewinding head to replay your work on
top of it...
Applying: …
pragmatic guide to git by travis swicegood some rights reserved
90. Rebasing Branches
prompt> git checkout new-branch
Switched to branch 'new-branch'
prompt> git rebase 1a3cdc2
First, rewinding head to replay your work on
top of it...
Applying: …
pragmatic guide to git by travis swicegood some rights reserved
99. Viewing Remotes
prompt> git remote
prompt>
pragmatic guide to git by travis swicegood some rights reserved
100. Viewing Remotes
prompt> cd /usr/local
prompt> git remote
homebrew
roder
tswicegood
pragmatic guide to git by travis swicegood some rights reserved
106. Fetching Changes
prompt> git fetch <remote>
… example …
prompt> git fetch tswicegood
remote: Counting objects: 3, done.
… clipped …
* [new branch] master -> tswicegood/master
pragmatic guide to git by travis swicegood some rights reserved
107. Remote
Branches
pragmatic guide to git by travis swicegood some rights reserved
108. Remote Branches
prompt> git branch -r
tswicegood/master
… or everything at once …
prompt> git branch -a
* master
remotes/tswicegood/master
pragmatic guide to git by travis swicegood some rights reserved
109. You Still
Have to Merge
pragmatic guide to git by travis swicegood some rights reserved
111. Pulling Changes
prompt> git pull <remote> <branch>
… example …
prompt> git pull tswicegood master
… clipped …
* branch master -> FETCH_HEAD
Fast-forward
… clipped …
pragmatic guide to git by travis swicegood some rights reserved
112. Grokking Refspecs
prompt> git pull <remote> <branch>
… example …
prompt> git pull tswicegood master
… clipped …
* branch master -> FETCH_HEAD
Fast-forward
… clipped …
pragmatic guide to git by travis swicegood some rights reserved
113. Grokking Pull Refspecs
prompt> git pull <remote>
<remote branch>:<local branch>
… examples …
prompt> git pull tswicegood master
prompt> git pull tswicegood master:master
prompt> git pull tswicegood dev:my-dev
pragmatic guide to git by travis swicegood some rights reserved
114. Pulling
Part 2
pragmatic guide to git by travis swicegood some rights reserved
115. Pulling Changes
prompt> git pull --rebase <remote> <branch>
… example …
prompt> git pull --rebase tswicegood master
… clipped …
* branch master -> FETCH_HEAD
First, rewinding head to replay your work on
top of it... clipped …
pragmatic guide to git by travis swicegood some rights reserved
127. Travis Swicegood
travisswicegood.com
@tswicegood
travis@domain51.com
http://joind.in/2855
pragmatic guide to git by travis swicegood some rights reserved