This repository has been archived by the owner on Oct 14, 2019. It is now read-only.
/
git-quickref
205 lines (111 loc) · 4.46 KB
/
git-quickref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
flx-docs - git quickref
Felix C. Stegerman <flx@obfusk.net>
2012-07-31
--
=== Introduction ===
This is a quick reference for Git.
( Replace 'project' with an appropriate name for your project;
<edit> with your editor; <msg> with a message; and ... with the
appropriate file(s)/path(s)/argument(s); [...] is optional. )
=== Global setup (one time) ===
(Use your name and email instead of mine.)
$ git config --global user.name "Felix C. Stegerman"
$ git config --global user.email flx@obfusk.net
$ git config --global color.ui true
=== Creating a repository ===
=== Create a new project directory ===
$ cd .../dev # your development directory
$ mkdir project # your project directory
=== Use a (new/existing) project directory ===
$ cd project
$ git init . # create a repository
=== Add some files (for new projects) ===
$ <edit> README .gitignore # ignore e.g. *~
$ git add . # add all files in directory
=== Initial Commit ===
$ git commit -a -s -m '<msg>' # See policy ?!
=== Create a remote repository ===
$ cd ... # your git repository directory
$ mkdir project.git # your remote project directory
$ cd project.git
$ git init --bare . # create a repository
=== Add a remote repository ===
$ cd .../project # your project directory
$ git remote add origin .../project.git
# your remote project directory
$ git push origin master # first push
=== Push to remote repository ===
$ git push [<remote> [<branch>]]
=== Development ===
(In your project directory.)
$ <edit> ... # 1. edit
$ git add ... # ( 2. add new files )
$ git commit [-a] -s -m '...' # 3. commit; see policy ?!
$ git push # ( 4. push )
$ git status # in between actions
=== Clone a repository ===
$ git clone .../project.git project
# to use another name, change the last argument
=== Useful commands & help ===
=== Help ===
$ man git
$ man git-<command> # e.g. git-status
$ git help
$ git help <command>
=== Miscellaneous ===
$ git add . # adds current dir, recursively
$ git add -u # adds/removes modified/deleted files
$ git status [-s]
$ git show-branch -a
$ git config [--global] -l
$ git branch --set-upstream master origin/master
# set upstream branch; now >> git status << will inform you if
# your branch is ahead of upstream, and >> git push/pull << will
# work w/o specifying a remote
$ git fetch/merge/pull # see docs first!
$ git show # ... TODO ...
$ git remote set-head origin -d # remove annoying orgin/HEAD
=== Log ===
$ git log [-p] [-<n>] # -p = w/ diffs; -2 = last 2
$ git log [--oneline] [--graph]
$ git log [--stat] [--summary]
... TODO ...
=== Diff ===
$ git diff # index vs. workdir
$ git diff HEAD # commit vs. workdir
$ git diff --cached # commit vs. index
... TODO ...
=== Instaweb ===
$ git instaweb --httpd=webrick [--local] [--port=...]
$ git instaweb --stop
$ git config instaweb.local true # optional defaults (per
$ git config instaweb.http webrick # repository; you can also
$ git config instaweb.port ... # use --global)
=== Tools ===
* gitx
* gitk
* git gui
* git-cola
* ...
... TODO ...
See [1], [2].
=== Branching ===
(You usually start out with only a master branch.)
$ git branch [-a] # list branches
$ git show-branch [-a] # show (all) branches
$ git branch foo # create new branch foo
$ git checkout foo # switch to branch foo
$ git checkout -b foo # create & switch to foo
$ git merge foo # merge branch foo into current
# branch
$ git branch -d foo # delete branch foo (if merged)
$ git branch -D foo # BE CAREFUL; delete branch foo
$ git help ... # for more info, options
... TODO ...
See [2].
=== Policy ===
... TODO ...
=== References ===
[1] Git reference http://gitref.org/
[2] Pro Git http://git-scm.com/book
--